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

Hostname completion for ssh and telnet commands

This commit is contained in:
Junegunn Choi
2013-11-29 18:08:22 +09:00
parent 9a3cddc92e
commit faff17b2a9
2 changed files with 36 additions and 1 deletions

View File

@@ -95,6 +95,22 @@ _fzf_kill_completion() {
fi
}
_fzf_host_completion() {
if [ "${COMP_WORDS[COMP_CWORD-1]}" = '-l' ]; then
return 1
fi
local selected
tput sc
selected=$(grep -v '^\s*\(#\|$\)' /etc/hosts | awk '{print $2}' | sort -u | fzf $FZF_COMPLETION_OPTS)
tput rc
if [ -n "$selected" ]; then
COMPREPLY=( "$selected" )
return 0
fi
}
complete -F _fzf_opts_completion fzf
# Directory
@@ -123,3 +139,8 @@ done
# Kill completion
complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill
# Host completion
for cmd in "ssh telnet"; do
complete -F _fzf_host_completion -o default -o bashdefault $cmd
done