From 2b19c0bc685fc2f726b977d161e6ce720a4d04a8 Mon Sep 17 00:00:00 2001 From: ptzz Date: Sat, 2 Jun 2018 03:40:33 +0200 Subject: [PATCH] [bash/zsh] Fix missing fuzzy completions (#1303) * [bash/zsh] Fix missing fuzzy completions `cat foo**` did not display the file `foobar` if there was a directory named `foo`. Fixes #1301 * [zsh] Evaluate completion prefix cat $HOME** cat ~username** cat ~username/foo** --- shell/completion.bash | 2 +- shell/completion.zsh | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/shell/completion.bash b/shell/completion.bash index b3d28f2..86b7852 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -148,7 +148,7 @@ __fzf_generic_path_completion() { base=${cur:0:${#cur}-${#trigger}} eval "base=$base" - dir="$base" + [[ $base = *"/"* ]] && dir="$base" while true; do if [ -z "$dir" ] || [ -d "$dir" ]; then leftover=${base/#"$dir"} diff --git a/shell/completion.zsh b/shell/completion.zsh index 2e25c58..1e3ced8 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -36,8 +36,7 @@ __fzfcmd_complete() { __fzf_generic_path_completion() { local base lbuf compgen fzf_opts suffix tail fzf dir leftover matches - # (Q) flag removes a quoting level: "foo\ bar" => "foo bar" - base=${(Q)1} + base=$1 lbuf=$2 compgen=$3 fzf_opts=$4 @@ -46,14 +45,14 @@ __fzf_generic_path_completion() { fzf="$(__fzfcmd_complete)" setopt localoptions nonomatch - dir="$base" + eval "base=$base" + [[ $base = *"/"* ]] && dir="$base" while [ 1 ]; do - if [[ -z "$dir" || -d ${~dir} ]]; then + if [[ -z "$dir" || -d ${dir} ]]; then leftover=${base/#"$dir"} leftover=${leftover/#\/} [ -z "$dir" ] && dir='.' [ "$dir" != "/" ] && dir="${dir/%\//}" - dir=${~dir} matches=$(eval "$compgen $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" ${=fzf} ${=fzf_opts} -q "$leftover" | while read item; do echo -n "${(q)item}$suffix " done)