m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-17 15:53:39 -05:00

Improve bash completion

- kill completion: do not even start fzf on non-empty word
- host completion: start fzf with initial query
This commit is contained in:
Junegunn Choi
2013-11-29 23:42:00 +09:00
parent d3742782f3
commit df663c4e41

View File

@@ -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,13 +97,13 @@ _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