summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorJay <jay@meangrape.com>2018-07-05 22:29:39 -0400
committerJunegunn Choi <junegunn.c@gmail.com>2018-07-06 11:29:39 +0900
commit6de1ad9d3dd4fdddf327f6201617409a8697dd43 (patch)
tree5156557bff8adfb3b4e1d8f806563c1d75fb6b75 /shell
parent5004ae345784811d14d6235df40244b85239b9b4 (diff)
[completion] Filter out non-hostnames in SSH config file (#1329)
* 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 **`
Diffstat (limited to 'shell')
-rw-r--r--shell/completion.bash2
-rw-r--r--shell/completion.zsh2
2 files changed, 2 insertions, 2 deletions
diff --git a/shell/completion.bash b/shell/completion.bash
index 86b78526..93369954 100644
--- a/shell/completion.bash
+++ b/shell/completion.bash
@@ -241,7 +241,7 @@ _fzf_complete_telnet() {
_fzf_complete_ssh() {
_fzf_complete '+m' "$@" < <(
- 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}') \
+ 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}') \
<(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
awk '{if (length($2) > 0) {print $2}}' | sort -u
diff --git a/shell/completion.zsh b/shell/completion.zsh
index 1e3ced8e..4df21b33 100644
--- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -114,7 +114,7 @@ _fzf_complete_telnet() {
_fzf_complete_ssh() {
_fzf_complete '+m' "$@" < <(
- command 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}') \
+ command 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}') \
<(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
awk '{if (length($2) > 0) {print $2}}' | sort -u