-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Use eval to evaluate $post variable as command. #4023
Conversation
With the current code, I get this command cat: command not found when using any keybinding that does _fzf_complete. Seen on Ubuntu 24.04.1 (GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)) Fixes: 561e0b0 ("[bash] Use `command` to “protect” further commands (junegunn#3462)") Signed-off-by: Thomas Martitz <[email protected]>
I can't reproduce the problem with |
Very strange. I don't know what's the difference then. On my system, the issue is typically triggered when I hit Here's the code, maybe it helps you to reproduce?
|
It seems that assigning the newline character to post='command -p cat'
for i in $post; do echo "Test 1: '$i'"; done
Test 1: 'command'
Test 1: '-p'
Test 1: 'cat'
IFS=$'\n'
for i in $post; do echo "Test 2: '$i'"; done
Test 2: 'command -p cat' Maybe like this ?2 --- a/shell/completion.bash
+++ b/shell/completion.bash
@@ -372,9 +372,9 @@ _fzf_complete() {
cmd="${COMP_WORDS[0]}"
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
cur=${cur:0:${#cur}-${#trigger}}
-
+ local IFS=$' \t\n' # normalize IFS
selected=$(
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \
FZF_DEFAULT_OPTS_FILE='' \
__fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | command tr '\n' ' ') Footnotes |
Seems to work as well. Not sure what's the better approach. While my proposed patch only affects the evaluation of |
In the meantime, I tried to get rid of the IFS override. I tried with I could verify with this simpler example: |
Mini Example: _complete() {
COMPREPLY=("$(cat)")
}
push() {
printf 1 | _complete
# _complete < <(printf 1)
}
complete -F push p When running it with Note complete 2 _complete() {
echo "PID of the current shell $$" >/tmp/log
echo "PID of the current bash process $BASHPID" >>/tmp/log
COMPREPLY=("$(cat)")
}
push() {
printf 1 | _complete
}
complete -F push p
cat /tmp/log
# PID of the current shell 93282
# PID of the current bash process 93294 With _complete() {
echo "PID of the current shell $$" >/tmp/log
echo "PID of the current bash process $BASHPID" >>/tmp/log
COMPREPLY=("$(cat)")
}
push() {
_complete < <(printf 1)
}
complete -F push p cat /tmp/log
# PID of the current shell 93441
# PID of the current bash process 93441 Summary: As long as push() {
(COMPREPLY=("$(printf 1)"))
}
complete -F push p
_fzf_complete --read0 "$@" < <(dirs -v | tr '\n' '\0') @Kugel - I wonder why you originally set Footnotes |
I don't remember actually. I'm using this for several years now. Maybe fzf behaved differently in past versions?
|
Thanks @LangLangBart for taking time to look into this.
|
With the current code, I get this
command cat: command not found
when using any keybinding that does _fzf_complete. Seen on Ubuntu 24.04.1 (GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu))
Fixes: 561e0b0 ("[bash] Use
command
to “protect” further commands (#3462)")