Hostname completion for ssh and telnet commands
This commit is contained in:
parent
9a3cddc92e
commit
faff17b2a9
16
README.md
16
README.md
@ -270,6 +270,8 @@ over time*
|
|||||||
|
|
||||||
### bash
|
### bash
|
||||||
|
|
||||||
|
#### Files and directories
|
||||||
|
|
||||||
Fuzzy completion for files and directories can be triggered if the word before
|
Fuzzy completion for files and directories can be triggered if the word before
|
||||||
the cursor ends with the trigger sequence which is by default `**`.
|
the cursor ends with the trigger sequence which is by default `**`.
|
||||||
|
|
||||||
@ -297,7 +299,9 @@ cd **<TAB>
|
|||||||
cd ~/github/fzf**<TAB>
|
cd ~/github/fzf**<TAB>
|
||||||
```
|
```
|
||||||
|
|
||||||
Fuzzy completion for PIDs are provided for kill command. In this case
|
#### Process IDs
|
||||||
|
|
||||||
|
Fuzzy completion for PIDs is provided for kill command. In this case
|
||||||
there is no trigger sequence, just press tab key after kill command.
|
there is no trigger sequence, just press tab key after kill command.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@ -305,6 +309,16 @@ there is no trigger sequence, just press tab key after kill command.
|
|||||||
kill -9 <TAB>
|
kill -9 <TAB>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Host names
|
||||||
|
|
||||||
|
For ssh and telnet command, fuzzy completion for host names is provided. The
|
||||||
|
names are extracted from /etc/hosts file.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ssh <TAB>
|
||||||
|
telnet <TAB>
|
||||||
|
```
|
||||||
|
|
||||||
#### Settings
|
#### Settings
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -95,6 +95,22 @@ _fzf_kill_completion() {
|
|||||||
fi
|
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
|
complete -F _fzf_opts_completion fzf
|
||||||
|
|
||||||
# Directory
|
# Directory
|
||||||
@ -123,3 +139,8 @@ done
|
|||||||
# Kill completion
|
# Kill completion
|
||||||
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
|
||||||
|
for cmd in "ssh telnet"; do
|
||||||
|
complete -F _fzf_host_completion -o default -o bashdefault $cmd
|
||||||
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user