Skip to content

Instantly share code, notes, and snippets.

@jmcantrell
Last active February 28, 2017 20:14
Show Gist options
  • Save jmcantrell/7f5a866851082288420e68318f0211dc to your computer and use it in GitHub Desktop.
Save jmcantrell/7f5a866851082288420e68318f0211dc to your computer and use it in GitHub Desktop.
Make hosts in included config files available for completion
--- /usr/share/zsh/functions/Completion/Unix/_ssh 2016-12-22 11:27:00.000000000 -0800
+++ packages/base/.local/share/zsh/functions/_ssh 2017-02-26 22:37:47.513422235 -0800
@@ -681,16 +681,21 @@
fi
if [[ -r $config ]]; then
local key hosts host
- while IFS=$'=\t ' read -r key hosts; do
- if [[ "$key" == (#i)host ]]; then
- for host in ${(z)hosts}; do
- case $host in
- (*[*?]*) ;;
- (*) config_hosts+=("$host") ;;
- esac
- done
- fi
- done < "$config"
+ local filename configs=($config)
+ grep '^Include\b' "$config" | sed 's/\s\+/ /g' | cut -d' ' -f2 |
+ while read -r filename; do
+ config=$HOME/.ssh/$filename
+ while IFS=$'=\t ' read -r key hosts; do
+ if [[ "$key" == (#i)host ]]; then
+ for host in ${(z)hosts}; do
+ case $host in
+ (*[*?]*) ;;
+ (*) config_hosts+=("$host") ;;
+ esac
+ done
+ fi
+ done < "$config"
+ done
if (( ${#config_hosts} )); then
_wanted hosts expl 'remote host name' \
compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment