-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to setup autocompletion? #288
Comments
Yep, in the shell hook will work nicely. Be aware that # Add argcomplete as a propagated ros2cli dependency.
# https://github.com/ros2/ros2cli/pull/564
# https://github.com/ros2/ros2cli/blob/26715cbb0948258d6f04b94c909d035c5130456a/ros2cli/ros2cli/cli.py#L45
ros2cli = rosSuper.ros2cli.overrideAttrs ({ propagatedBuildInputs ? [ ], ... }: {
propagatedBuildInputs = propagatedBuildInputs ++ [ rosSelf.pythonPackages.argcomplete ];
}); |
and how would I do that? For ros2 I tried to use the following in my setup shellHook = ''
eval ${pkgs.python310Packages.argcomplete}/bin/register-python-argcomplete ros2
eval ${pkgs.python310Packages.argcomplete}/bin/register-python-argcomplete colcon
eval ${pkgs.python310Packages.argcomplete}/bin/register-python-argcomplete rosidl
''; |
That looks good to me. I have a more developed setup here (see the shell hook and setup script): https://github.com/hacker1024/nix-ros-workspace/blob/master/packages/ros/build-ros-workspace/default.nix |
Yeah I saw your repo and took inspirations from there for my shell hook. But the autocompletion does not work. eval "$(register-python-argcomplete ros2)"
eval "$(register-python-argcomplete colcon)"
eval "$(register-python-argcomplete rosidl)" But it does not work when I put these commands into my shellHook. |
@hacker1024 I got it working using the setup script from your setup. But it only works with It works when I call |
That is expected. The |
Leaving a few tips on how to automatically setup zsh autocompletion. As hacker1024 said, this is a general issue with non-bash shells integration with What you want to do is rely on native shell auto-complete script discovery.
(pkgs.runCommand "ros-autocompletions" { } ''
for dir in {bash-completion/completions,zsh/site-functions}; do
mkdir -p $out/share/$dir
for program in {ros2,colcon,rosidl}; do
${pkgs.python3.pkgs.argcomplete}/bin/register-python-argcomplete $program > $out/share/$dir/_$program
done
done
'') (Ideally these should be part of the corresponding packages' derivations) You can use the zsh-completion-sync plugin, which will take care of fetching the proper dirs from |
@liarokapisv Thanks for your reply on this issue. Can you give a minimal working example? |
Basically, just put the above derivation in your {
inputs = {
ros-overlay.url = "github:lopsided98/nix-ros-overlay/master";
nixpkgs.follows = "ros-overlay/nixpkgs";
};
outputs = { self, nixpkgs, ros-overlay, ... }:
let
forAllSystems = (f: nixpkgs.lib.genAttrs [ "x86_64-linux" ] (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
ros-distro = pkgs.rosPackages.jazzy;
in
f {
inherit system pkgs ros-distro;
})
);
in
{
overlays.default = ros-overlay.overlays.default;
devShells = forAllSystems
({ pkgs, ros-distro, ... }:
{
default =
pkgs.mkShell
{
name = "ros-shell";
packages = with pkgs; [
ros-distro.ros-core
colcon
(pkgs.runCommand "ros-autocompletions" { } ''
for dir in {bash-completion/completions,zsh/site-functions}; do
mkdir -p $out/share/$dir
for program in {ros2,colcon,rosidl}; do
${pkgs.python3.pkgs.argcomplete}/bin/register-python-argcomplete $program > $out/share/$dir/_$program
done
done
'')
];
};
});
};
} Then just add the zsh-completion-sync plugin to your zsh config. |
Works for me. Thanks for this tip. |
hi,
|
This only works if you are using bash as a shell. |
You are right:
I see also that The previous solutions have a dependencies to the zsh-completion-sync that is not part of default omz plugins, it requires a little more configuration on the system level. Would it be a good thing to have the shellHook solution merged in the README.md ? |
If we add the autocomplete support to the appropriate packages (by adding the |
I am using this overlay for ros1 and ros2 development. For ros1 autocompletion was enable after sourcing
devel/setup.zsh
. For ros2 someting likeeval "$(register-python-argcomplete colcon)"
would be needed (see this issue).What is the best way to setup autocompletion for ros1 and ros2? Can I setup autocompletion in the
mkshell
shell-hook?The text was updated successfully, but these errors were encountered: