Skip to content
Myr

[shell] make `__fzf_list_hosts()` definable by the user

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Just like it’s already done for `_fzf_compgen_path()` and `_fzf_compgen_dir()` allow a user to easily define his own version of `__fzf_list_hosts()`. Also add some documentation on the expected “interface” of such custom function.

authored by Christoph Anton Mitterer · committed by Junegunn Choi · parent f1d306f · Browse files · 2 files+23 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>

Diff stats

2 files+23 added−13 removed

  • other:+23 added−13 removed

2 files+23 added−13 removed

modified:shell/completion.bash+11 added-6 removed
405 unmodified lines
406_fzf_proc_completion_post() {407 command awk '{print $2}'408}409410# To use custom hostname lists, override __fzf_list_hosts.411# The function is expected to print hostnames, one per line as well as in the412# desired sorting and with any duplicates removed, to standard output.413if ! declare -F __fzf_list_hosts > /dev/null; then410__fzf_list_hosts() {411 command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | command awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \412 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | command tr ',' '\n' | command tr -d '[' | command awk '{ print $1 " " $1 }') \413 <(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0') |414 command awk '{if (length($2) > 0) {print $2}}' | command sort -u415}414 __fzf_list_hosts() {415 command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | command awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \416 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | command tr ',' '\n' | command tr -d '[' | command awk '{ print $1 " " $1 }') \417 <(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0') |418 command awk '{if (length($2) > 0) {print $2}}' | command sort -u419 }420fi421422_fzf_host_completion() {423 _fzf_complete +m -- "$@" < <(__fzf_list_hosts)424}
111 unmodified lines
modified:shell/completion.zsh+12 added-7 removed
216 unmodified lines
217 fi218 command rm -f "$fifo"219}220221# To use custom hostname lists, override __fzf_list_hosts.222# The function is expected to print hostnames, one per line as well as in the223# desired sorting and with any duplicates removed, to standard output.224if ! declare -f __fzf_list_hosts > /dev/null; then221__fzf_list_hosts() {222 setopt localoptions nonomatch223 command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \224 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \225 <(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0') |226 awk '{if (length($2) > 0) {print $2}}' | sort -u227}225 __fzf_list_hosts() {226 setopt localoptions nonomatch227 command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \228 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \229 <(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0') |230 awk '{if (length($2) > 0) {print $2}}' | sort -u231 }232fi233234_fzf_complete_telnet() {235 _fzf_complete +m -- "$@" < <(__fzf_list_hosts)236}
111 unmodified lines