summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2018-02-15 11:56:07 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2018-02-15 18:21:02 +0900
commitcce6aef557b22e28269e1b435e1079a694d43f92 (patch)
treec7fcf77df54bcff403e9acbd58c39b49c03fefdc /shell
parenteb3afc03b57a20d1062880efe8e000abceeba3ee (diff)
downloadfzf-cce6aef557b22e28269e1b435e1079a694d43f92.tar.gz
[bash] Fix extra space issue of dynamic completion with 'nospace'
Close #1203
Diffstat (limited to 'shell')
-rw-r--r--shell/completion.bash19
1 files changed, 12 insertions, 7 deletions
diff --git a/shell/completion.bash b/shell/completion.bash
index d2287c84..9f079b27 100644
--- a/shell/completion.bash
+++ b/shell/completion.bash
@@ -38,9 +38,9 @@ __fzfcmd_complete() {
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
}
-_fzf_orig_completion_filter() {
- sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2";/' |
- awk -F= '{gsub(/[^A-Za-z0-9_= ;]/, "_", $1); print $1"="$2}'
+__fzf_orig_completion_filter() {
+ sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2"; [[ "\1" = *" -o nospace "* ]] \&\& [[ ! "$__fzf_nospace_commands" = *" \3 "* ]] \&\& __fzf_nospace_commands="$__fzf_nospace_commands \3 ";/' |
+ awk -F= '{gsub(/[^A-Za-z0-9_= ;]/, "_", $1);}1'
}
_fzf_opts_completion() {
@@ -127,8 +127,12 @@ _fzf_handle_dynamic_completion() {
ret=$?
# _completion_loader may not have updated completion for the command
if [ "$(complete -p "$cmd")" != "$orig_complete" ]; then
- eval "$(complete | command grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)"
- eval "$orig_complete"
+ eval "$(complete | command grep " -F.* $orig_cmd$" | __fzf_orig_completion_filter)"
+ if [[ "$__fzf_nospace_commands" = *" $orig_cmd "* ]]; then
+ eval "${orig_complete/ -F / -o nospace -F }"
+ else
+ eval "$orig_complete"
+ fi
fi
return $ret
fi
@@ -156,6 +160,7 @@ __fzf_generic_path_completion() {
printf "%q$3 " "$item"
done)
matches=${matches% }
+ [[ -z "$3" ]] && [[ "$__fzf_nospace_commands" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches "
if [ -n "$matches" ]; then
COMPREPLY=( "$matches" )
else
@@ -278,9 +283,9 @@ a_cmds="
x_cmds="kill ssh telnet unset unalias export"
# Preserve existing completion
-eval $(complete |
+eval "$(complete |
sed -E '/-F/!d; / _fzf/d; '"/ ($(echo $d_cmds $a_cmds $x_cmds | sed 's/ /|/g; s/+/\\+/g'))$/"'!d' |
- _fzf_orig_completion_filter)
+ __fzf_orig_completion_filter)"
if type _completion_loader > /dev/null 2>&1; then
_fzf_completion_loader=1