-
Notifications
You must be signed in to change notification settings - Fork 21
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
Completions broken in zsh if completing with a path containing ~
or an environment variable
#315
Comments
Oh! I think I may have spotted it: $ ~/../../usr/bin/chezmoi_modify_manager -s a<tab> _chezmoi_modify_manager:2: no such file or directory: ~/../../usr/bin/chezmoi_modify_manager
$ $HOME/src/chmm/target/debug/chezmoi_modify_manager -s a _chezmoi_modify_manager:2: no such file or directory: $HOME/src/chmm/target/debug/chezmoi_modify_manager Probably it doesn't like the |
~
or an environment variable
Some zsh shenanigans I suspect. You can see what exactly zsh is trying to execute if you press |
First time I have read that output. It is rather long at 195 very very long lines. But from the the looks of it, the issue that somehow we end up with single quotes around things:
Which is odd... $ type -f _chezmoi_modify_manager 27m 54s
_chezmoi_modify_manager () {
source <( "${words[1]}" --bpaf-complete-rev=7 "${words[@]:1}" )
} It could be something with the zsh framework/addons etc I use (if you can't reproduce this). Unfortunately the one I use (zsh4humans) has effectively stopped being maintained in recent years. As it suits my needs perfectly and has very good latency I have yet to try to switch to something else. Worth noting is that commands other than things using bpaf seem unaffected. Even those that call the binary to generate completions dynamically (such as |
For what it is worth, the completions for # Prepare the command to obtain completions
requestComp="${words[1]} __complete ${words[2,-1]}"
if [ "${lastChar}" = "" ]; then
# If the last parameter is complete (there is a space following it)
# We add an extra empty parameter so we can indicate this to the go completion code.
__chezmoi_debug "Adding extra empty parameter"
requestComp="${requestComp} \"\""
fi
__chezmoi_debug "About to call: eval ${requestComp}"
# Use eval to handle any environment variables and such
out=$(eval ${requestComp} 2>/dev/null) That comment above the I believe (from a previous bug report last year or possibly before) that chezmoi also uses a library similar to bpaf/clap etc that does the actual completions and arg parsing. I don't remember the name of it, as I don't know Go. |
What you pasted is basically a fix :) I made this change to a script from line="${words[1]} --bpaf-complete-rev=4 ${words[2,-1]}"
if [[ ${words[-1]} == "" ]]; then
line="${line} \"\""
fi
IFS=$'\n' lines=$(eval ${line}) |
I'm not keen on the use of eval though! There might be some expansion modifier that does what you want... Zsh has a ton of those. Also check license of where I took that from (some random go library). I don't know how prevalent copyleft licences are in that ecosystem. |
Just a question: did you ever incorporate the fix for this? |
Got distracted by some other stuff. I can add this along with some other changes I'm working if that's a problem for you. |
Sounds good, though issue #303 is also a problem for me (and that one is probably harder to fix) |
Ack. Will try to give them more priority now that I have better tests (not merged yet) in place. |
COMP_WORDS/words gets filled with exact contents of the command line, this includes application name. Usually application is invoked via $PATH so this works fine, but it is also possible to specify a path containing ~ or env variables. This is usually expanded by shell. this expansion is not performed by <( xxx ) so we are doing it by hand instead Fixes #315
This is a weird one:
The binary in /usr/bin is the one in path. And it is the same version as from my source dir (except built with Arch Linux AUR as a system package). Huh?
_chezmoi_modify_manager
is in/usr/share/zsh/site-functions/_chezmoi_modify_manager
(installed by Arch Linux package manager as part of AUR package).Relevant system info:
The text was updated successfully, but these errors were encountered: