diff --git a/README.md b/README.md index 90c15cd..8f8ec3c 100644 --- a/README.md +++ b/README.md @@ -305,11 +305,11 @@ kill -9 #### Host names For ssh and telnet commands, fuzzy completion for host names is provided. The -names are extracted from /etc/hosts file. +names are extracted from /etc/hosts and ~/.ssh/config. ```sh -ssh -telnet +ssh ** +telnet ** ``` #### Settings diff --git a/fzf-completion.bash b/fzf-completion.bash index 8d5b903..c5d6343 100644 --- a/fzf-completion.bash +++ b/fzf-completion.bash @@ -31,12 +31,12 @@ _fzf_opts_completion() { } _fzf_generic_completion() { - local cur base dir leftover matches + local cur base dir leftover matches trigger COMPREPLY=() - FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**} + trigger=${FZF_COMPLETION_TRIGGER:-**} cur="${COMP_WORDS[COMP_CWORD]}" - if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then - base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}} + if [[ ${cur} == *"$trigger" ]]; then + base=${cur:0:${#cur}-${#trigger}} eval base=$base dir="$base" @@ -97,10 +97,11 @@ _fzf_kill_completion() { } _fzf_telnet_completion() { - local cur prev selected + local cur selected trigger + trigger=${FZF_COMPLETION_TRIGGER:-**} cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - [[ "$cur" =~ ^- || "$prev" =~ ^- ]] && return 1 + [[ ${cur} == *"$trigger" ]] || return 1 + cur=${cur:0:${#cur}-${#trigger}} tput sc selected=$(grep -v '^\s*\(#\|$\)' /etc/hosts | awk '{print $2}' | sort -u | fzf $FZF_COMPLETION_OPTS -q "$cur") @@ -113,10 +114,11 @@ _fzf_telnet_completion() { } _fzf_ssh_completion() { - local cur prev selected + local cur selected trigger + trigger=${FZF_COMPLETION_TRIGGER:-**} cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - [[ "$cur" =~ ^- || "$prev" =~ ^- ]] && return 1 + [[ ${cur} == *"$trigger" ]] || return 1 + cur=${cur:0:${#cur}-${#trigger}} tput sc selected=$(cat \