diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2013-11-29 23:42:00 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2013-11-29 23:42:00 +0900 |
| commit | df663c4e418347c0af0c2db204ec260e94cc092e (patch) | |
| tree | 390db1796f6100218be6b732587f2e82c434b447 | |
| parent | d3742782f36993ff6dfd85e66e8d364268b29f4f (diff) | |
| download | fzf-df663c4e418347c0af0c2db204ec260e94cc092e.tar.gz | |
Improve bash completion
- kill completion: do not even start fzf on non-empty word
- host completion: start fzf with initial query
| -rw-r--r-- | fzf-completion.bash | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/fzf-completion.bash b/fzf-completion.bash index 2ffe7338..e1c3fa31 100644 --- a/fzf-completion.bash +++ b/fzf-completion.bash @@ -31,11 +31,10 @@ _fzf_opts_completion() { } _fzf_generic_completion() { - local cur prev opts base dir leftover matches + local cur base dir leftover matches COMPREPLY=() FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**} cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}} eval base=$base @@ -84,6 +83,8 @@ _fzf_dir_completion() { } _fzf_kill_completion() { + [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1 + local selected tput sc selected=$(ps -ef | sed 1d | fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ') @@ -96,17 +97,17 @@ _fzf_kill_completion() { } _fzf_host_completion() { - if [ "${COMP_WORDS[COMP_CWORD-1]}" = '-l' ]; then - return 1 - fi + local cur prev selected + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + [ "$cur" = '-l' -o "$prev" = '-l' ] && return 1 - local selected tput sc - selected=$(grep -v '^\s*\(#\|$\)' /etc/hosts | awk '{print $2}' | sort -u | fzf $FZF_COMPLETION_OPTS) + selected=$(grep -v '^\s*\(#\|$\)' /etc/hosts | awk '{print $2}' | sort -u | fzf $FZF_COMPLETION_OPTS -q "$cur") tput rc if [ -n "$selected" ]; then - COMPREPLY=( "$selected" ) + COMPREPLY=("$selected") return 0 fi } |
