ros2cli: Autocomplete fails while using zsh.
Bug report
Required Info:
- Operating System:
- Ubuntu 18.04
- Installation type:
- binaries
- Version or commit hash:
- Dashing / Eloquent
- DDS implementation:
- ALL
- Client library (if applicable):
- N/A
Steps to reproduce issue
I use zsh as my shell, but I find some problems while using <tab> to autocomplete.
- While I type
ros2 run <tab>, it works well. - However when I type
ros2 run d<tab>, it can’t show the packages which starts with ‘d’.
Additional information
After some debugging, I find that the behavior is related to argcomplete library in Python 3.
If I remove the library rm -rf ~/.local/lib/python3.6/site-packages/argcomplete*, zsh works well again.
I’m not pretty sure what the root cause is.
Maybe argcomplete library does not support zsh well.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 28 (11 by maintainers)
Having the same issue with Zsh and ROS2 Galactic too.
But I found a solution in https://kislyuk.github.io/argcomplete/#zsh-support
By adding these lines to
.zshrcthe argcompletion is succesfully enabled.(Thanks to https://github.com/ros2/ros2cli/issues/534#issuecomment-957905035, I removed the unnessecary
autoload -U bashcompinit \ bashcompinit)Instead of running
eval "$(register-python-argcomplete3 ros2)"every time after sourcingsetup.zsh, I made a modification in/opt/ros/galactic/share/rosidl_cli/environment/rosidl-argcomplete.zsh. I removed/commented the line:Then
ros2tab completion works. This has to do withcompinitbeing called too many times (see also https://stackoverflow.com/questions/67136714/how-to-properly-call-compinit-and-bashcompinit-in-zsh ).I’m not sure what a final fix should be, especially since tab completion for
colconstill doesn’t work with this change (theeval "$(register-python-argcomplete3 colcon)"is still needed for that).That worked for me, thanks for sharing!
Huh, interesting. So it turns out that we are already calling
eval "$(register-python-argcomplete ros2)"when sourcing for the zsh shell: https://github.com/ros2/ros2cli/blob/master/ros2cli/completion/ros2-argcomplete.zsh . And I verified locally that those files do indeed get sourced when source/opt/ros/rolling/setup.zsh. However, completion doesn’t work anyway; you have to re-run theeval, as everyone above found out.Actually, I found out that after sourcing
/opt/ros/rolling/setup.zsh, it is enough to do:That suggests to me that something else later in the sourcing process is unregistering what was already registered. Someone would need to look deeper into it to find out exactly why this isn’t working as expected.
Hi, I’m having the same problem as @ferrolho with
zshversion 5.8, and with both Foxy and Galaxy I’m unable to tab complete anything with theros2command.I will add that
zshcan tab complete parameters with any command exceptros2. For exampleapt se<tab>will produceapt search, butros2 lau<tab>will not complete toros2 launchHi! I have just installed ROS 2 (Galactic) for the first time on my machine (Ubuntu 20.04). I am also a user of ZSH, and for some reason the autocomplete isn’t working; but it works on the Bash. Some more info:
Fixed by #750
I am using Ubuntu 20.04 and Foxy, I have ZSH and oh-my-zsh installed. I needed to do the following to fix this issue.
Maybe rather than removing the
compinitcall it should be replaced with a check and call? As far as I’ve tested,compinitsets the variable_comps, so it could be something like:This way neither completion script ordering nor the possible
compinitcall in.zshrcdoesn’t matter.Edit: NVM had similar problem, but I’m not sure whether their solution works as intended - it calls
compiniteither way but with a flag (?), which doesn’t change the fact that it clears previous completions.For testing I removed the line
autoload -U +X compinit && compinitfrom the following files:In order to make it work properly I have to add above line in my .zshrc before sourcing ROS workspace (and colcon-argcomplete). Whithout it it does not work. So it seems to be mandatory.
@hardesh I think I was on to something with
compinitbeing called too often. What I hadn’t tried to figure out is whycompinitis being called inrosidl-argcomplete.zsh, where else it’s being called, and what would be the right (single) spot to do it.@dirk-thomas Thank you for the suggestion. The patch works perfectly!!! It frustrated me a long time about the argcomplete. You can close the issue if you think it’s OK.
I can reproduce the problem with Eloquent (using
5.4.2-3ubuntu3.1). In Foxy it is working though (using5.8-3ubuntu1).I think this is a duplicate of kislyuk/argcomplete#258. Either you use a newer version of
zshor you have to patch the function_bash_completemanually (https://github.com/zsh-users/zsh/commit/e2f793e7df7214cc3d80e2fcfe961ed087c860ab):type
which _bash_completecopy-n-past the whole function, but insert the
-1to the following line:(( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX ))(( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT-1]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX ))