mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 12:55:17 +00:00
Make host name completion require trigger sequence (#13)
This commit is contained in:
parent
76fe23b928
commit
33b28be941
@ -305,11 +305,11 @@ kill -9 <TAB>
|
|||||||
#### Host names
|
#### Host names
|
||||||
|
|
||||||
For ssh and telnet commands, fuzzy completion for host names is provided. The
|
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
|
```sh
|
||||||
ssh <TAB>
|
ssh **<TAB>
|
||||||
telnet <TAB>
|
telnet **<TAB>
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Settings
|
#### Settings
|
||||||
|
@ -31,12 +31,12 @@ _fzf_opts_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_generic_completion() {
|
_fzf_generic_completion() {
|
||||||
local cur base dir leftover matches
|
local cur base dir leftover matches trigger
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**}
|
trigger=${FZF_COMPLETION_TRIGGER:-**}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then
|
if [[ ${cur} == *"$trigger" ]]; then
|
||||||
base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}}
|
base=${cur:0:${#cur}-${#trigger}}
|
||||||
eval base=$base
|
eval base=$base
|
||||||
|
|
||||||
dir="$base"
|
dir="$base"
|
||||||
@ -97,10 +97,11 @@ _fzf_kill_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_telnet_completion() {
|
_fzf_telnet_completion() {
|
||||||
local cur prev selected
|
local cur selected trigger
|
||||||
|
trigger=${FZF_COMPLETION_TRIGGER:-**}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
[[ ${cur} == *"$trigger" ]] || return 1
|
||||||
[[ "$cur" =~ ^- || "$prev" =~ ^- ]] && return 1
|
cur=${cur:0:${#cur}-${#trigger}}
|
||||||
|
|
||||||
tput sc
|
tput sc
|
||||||
selected=$(grep -v '^\s*\(#\|$\)' /etc/hosts | awk '{print $2}' | sort -u | fzf $FZF_COMPLETION_OPTS -q "$cur")
|
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() {
|
_fzf_ssh_completion() {
|
||||||
local cur prev selected
|
local cur selected trigger
|
||||||
|
trigger=${FZF_COMPLETION_TRIGGER:-**}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
[[ ${cur} == *"$trigger" ]] || return 1
|
||||||
[[ "$cur" =~ ^- || "$prev" =~ ^- ]] && return 1
|
cur=${cur:0:${#cur}-${#trigger}}
|
||||||
|
|
||||||
tput sc
|
tput sc
|
||||||
selected=$(cat \
|
selected=$(cat \
|
||||||
|
Loading…
Reference in New Issue
Block a user