diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2023-10-03 20:04:56 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2023-10-04 21:43:11 +0900 |
| commit | 488a236b7a4d01e910e0ac80b4794a7a054fb3a8 (patch) | |
| tree | a10b1994d626ca98a989b888f4b524f2a5077ae2 /shell | |
| parent | e833823e15833122881a2cab333124c23fcc6ba5 (diff) | |
| download | fzf-488a236b7a4d01e910e0ac80b4794a7a054fb3a8.tar.gz | |
[shell] Avoid side-effects during eval (#3459)
Take two.
* Avoid eval if the prefix contains `:=`
* This is not to evaluate variable assignment. e.g. ${FOO:=BAR}
* [zsh] Prevent `>(...)` form
* Suppress error message from prefix evaluation
* Stop completion when prefix evaluation failed
Thanks to @calestyo
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/completion.bash | 6 | ||||
| -rw-r--r-- | shell/completion.zsh | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/shell/completion.bash b/shell/completion.bash index a51713c6..fb0b6c83 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -170,9 +170,9 @@ __fzf_generic_path_completion() { COMPREPLY=() trigger=${FZF_COMPLETION_TRIGGER-'**'} cur="${COMP_WORDS[COMP_CWORD]}" - if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *'<('* ]] && [[ $cur != *'`'* ]]; then + if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then base=${cur:0:${#cur}-${#trigger}} - eval "base=$base" + eval "base=$base" 2> /dev/null || return dir= [[ $base = *"/"* ]] && dir="$base" @@ -235,7 +235,7 @@ _fzf_complete() { cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}" trigger=${FZF_COMPLETION_TRIGGER-'**'} cur="${COMP_WORDS[COMP_CWORD]}" - if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *'<('* ]] && [[ $cur != *'`'* ]]; then + if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then cur=${cur:0:${#cur}-${#trigger}} selected=$(FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $str_arg" __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | tr '\n' ' ') diff --git a/shell/completion.zsh b/shell/completion.zsh index fe62b9a8..1e7d6f10 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -137,10 +137,10 @@ __fzf_generic_path_completion() { tail=$6 setopt localoptions nonomatch - if [[ $base = *'$('* ]] || [[ $base = *'<('* ]] || [[ $base = *'`'* ]]; then + if [[ $base = *'$('* ]] || [[ $base = *'<('* ]] || [[ $base = *'>('* ]] || [[ $base = *':='* ]] || [[ $base = *'`'* ]]; then return fi - eval "base=$base" + eval "base=$base" 2> /dev/null || return [[ $base = *"/"* ]] && dir="$base" while [ 1 ]; do if [[ -z "$dir" || -d ${dir} ]]; then @@ -307,7 +307,7 @@ fzf-completion() { d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}) [ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}} - if [[ $prefix = *'$('* ]] || [[ $prefix = *'<('* ]] || [[ $prefix = *'`'* ]]; then + if [[ $prefix = *'$('* ]] || [[ $prefix = *'<('* ]] || [[ $prefix = *'>('* ]] || [[ $prefix = *':='* ]] || [[ $prefix = *'`'* ]]; then return fi [ -n "${tokens[-1]}" ] && lbuf=${lbuf:0:-${#tokens[-1]}} |
