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

Re: How to get started with the completion system



On Jul 21,  8:37am, Jesper Holmberg wrote:
} Subject: How to get started with the completion system
}
} I am afraid this is quite a stupid question, but I'm looking for
} information on how to get started customizing the (new) completion system.

Probably the best place to start is PWS's Zsh User Guide:

	http://zsh.sunsite.dk/Guide/

} More specifically, I'd like scp to know my account names on remote hosts
} that I log into, and also maintain a list of these remote hosts, so that I
} can type "scp ./try.txt  je <TAB> @ hos <TAB>" and have the parts before and
} after the at-sign completed.

There's been quite a bit of discussion about this on the mailing lists,
some of it quite recent.  Unfortunately www.zsh.org is unreachable right
now (at least, I can't get to it) so I can't locate any examples.

So, here's what I use for ssh/scp; I don't promise it works perfectly,
because for one thing there is a known shortcoming in the way the
_combination utility (which is used by the _ssh completer) selects from
among multiple tags when generating listings, so you sometimes get more
choices than you expect; but it's mostly right:

----------

zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''

zstyle ':completion:*:scp:*' tag-order \
	'hosts:-host hosts:-domain:domain hosts:-ipaddr:IP\ address *'
zstyle ':completion:*:scp:*' group-order \
	users files all-files hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order \
	users 'hosts:-host hosts:-domain:domain hosts:-ipaddr:IP\ address *'
zstyle ':completion:*:ssh:*' group-order \
	hosts-domain hosts-host users hosts-ipaddr

zstyle ':completion:*:(ssh|scp):*:hosts-host' ignored-patterns \
	'*.*' loopback localhost
zstyle ':completion:*:(ssh|scp):*:hosts-domain' ignored-patterns \
	'<->.<->.<->.<->' '^*.*' '*@*'
zstyle ':completion:*:(ssh|scp):*:hosts-ipaddr' ignored-patterns \
	'^<->.<->.<->.<->' '127.0.0.<->'
zstyle ':completion:*:(ssh|scp):*:users' ignored-patterns \
	adm bin daemon halt lp named shutdown sync

zstyle -e ':completion:*:(ssh|scp):*' hosts 'reply=(
	${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) \
			/dev/null)"}%%[# ]*}//,/ }
	${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*}
	)'

zstyle ':completion:*:(ssh|scp):*:my-accounts' users-hosts \
	jesper.holmberg.5791@xxxxxxxxxxxxx

----------

Obviously I edited that last one.  You can add more of your own user@host
account names to the last line there.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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