Skip to content
Myr

[completion] Filter out non-hostnames in SSH config file (#1329)

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

* Correctly exclude SSH config options with Host SSH config files have 14 options containing 'Host'. Previously The zsh and bash completion scripts would include lines containing these options when doing command-line completion of SSH hosts with `ssh **`. This commit fixes that problem by only including lines with 'host '. * Don't autocomplete SSH hostnames using ? SSH config files support ? as well as * for wildcards in Host lines. This commit excludes lines containing ? for zsh/bash command line completeion using `ssh **`

authored by Jay · committed by Junegunn Choi · parent 5004ae3 · Browse files · 2 files+2 added−2 removed
This commit

State

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

Diff stats

2 files+2 added−2 removed

  • other:+2 added−2 removed

2 files+2 added−2 removed

modified:shell/completion.bash+1 added-1 removed
239 unmodified lines
240}241242_fzf_complete_ssh() {243 _fzf_complete '+m' "$@" < <(244 cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}') \244 cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host ' | command grep -v '[*?]' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}') \245 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \246 <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |247 awk '{if (length($2) > 0) {print $2}}' | sort -u248 )
84 unmodified lines
modified:shell/completion.zsh+1 added-1 removed