Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completing from different ssh config file



* Peter Stephenson [2006.11.14 07:15]:
> Index: Completion/Unix/Command/_ssh
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ssh,v
> retrieving revision 1.29
> diff -u -r1.29 _ssh
> --- Completion/Unix/Command/_ssh	3 Oct 2006 16:24:51 -0000	1.29
> +++ Completion/Unix/Command/_ssh	14 Nov 2006 11:53:15 -0000
> @@ -323,6 +323,8 @@
> 
>  _ssh_hosts () {
>    local -a config_hosts
> +  local config
> +  integer ind
> 
>    if [[ "$IPREFIX" == *@ ]]; then
>      _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@"
> @@ -330,7 +332,12 @@
>      _combination -s '[:@]' my-accounts users-hosts \
>        ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@"
>    fi
> -  if [[ -r "$HOME/.ssh/config" ]]; then
> +  if (( ind = ${words[(I)-F]} )); then
> +    config=$words[ind+1]
> +  else
> +    config="$HOME/.ssh/config"
> +  fi
> +  if [[ -r $config ]]; then
>      local IFS=$'\t ' key hosts host
>      while read key hosts; do
>        if [[ "$key" == (#i)host ]]; then
> @@ -341,7 +348,7 @@
>  	    esac
>  	 done
>        fi
> -    done < "$HOME/.ssh/config"
> +    done < "$config"
>      if (( ${#config_hosts} )); then
>        _wanted hosts expl 'remote host name' \
>  	compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts

Very nice. However for it to work perfectly, I had
to change the assignment to:

config=${~words[ind+1]}

In order for "~" to get expanded. Perhaps it's
safer instead of relying on globsubst to be set?

Thansk a lot!

-- 
JR



Messages sorted by: Reverse Date, Date, Thread, Author