mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-26 14:56:30 +00:00
Fix host completion to include ssh_config entries (#13)
This commit is contained in:
parent
622c54f4a3
commit
76fe23b928
@ -96,7 +96,7 @@ _fzf_kill_completion() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_host_completion() {
|
_fzf_telnet_completion() {
|
||||||
local cur prev selected
|
local cur prev selected
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
@ -112,6 +112,25 @@ _fzf_host_completion() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fzf_ssh_completion() {
|
||||||
|
local cur prev selected
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
[[ "$cur" =~ ^- || "$prev" =~ ^- ]] && return 1
|
||||||
|
|
||||||
|
tput sc
|
||||||
|
selected=$(cat \
|
||||||
|
<(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | grep -i ^host) \
|
||||||
|
<(grep -v '^\s*\(#\|$\)' /etc/hosts) | \
|
||||||
|
awk '{print $2}' | sort -u | fzf $FZF_COMPLETION_OPTS -q "$cur")
|
||||||
|
tput rc
|
||||||
|
|
||||||
|
if [ -n "$selected" ]; then
|
||||||
|
COMPREPLY=("$selected")
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
complete -F _fzf_opts_completion fzf
|
complete -F _fzf_opts_completion fzf
|
||||||
|
|
||||||
# Directory
|
# Directory
|
||||||
@ -141,7 +160,6 @@ done
|
|||||||
complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill
|
complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill
|
||||||
|
|
||||||
# Host completion
|
# Host completion
|
||||||
for cmd in "ssh telnet"; do
|
complete -F _fzf_ssh_completion -o default -o bashdefault ssh
|
||||||
complete -F _fzf_host_completion -o default -o bashdefault $cmd
|
complete -F _fzf_telnet_completion -o default -o bashdefault telnet
|
||||||
done
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user