mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-30 02:44:42 +01:00
SSH host auto completion plugin for making sysadmin life easier.
This commit is contained in:
parent
85426a57a2
commit
1a0c88ba29
1 changed files with 54 additions and 0 deletions
54
plugins/ssh/ssh.plugin.zsh
Normal file
54
plugins/ssh/ssh.plugin.zsh
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Plugin to make life of system administrators easier
|
||||
# Author: Nilesh (http://nileshgr.com)
|
||||
#
|
||||
# How to use this plugin
|
||||
#
|
||||
# Add in your zshrc before sourcing oh-my-zsh.zsh
|
||||
#
|
||||
# typeset -A ssh_hosts
|
||||
# ssh_hosts=('nickname' 'user@host1' \
|
||||
# 'nickname1' 'host2' \
|
||||
# 'nickname3' 'user2@host1' \
|
||||
# )
|
||||
#
|
||||
# Once you've done that, reload your zshrc and try
|
||||
# ssh <TAB>
|
||||
# It should give you the list of nicknames you specified (which can be selected by tabs)
|
||||
#
|
||||
# If you want to pass custom options to the ssh command, you can either
|
||||
# add them in the map as '-v user@host1'
|
||||
# or call the function as
|
||||
# ssh nickname <option>
|
||||
|
||||
if [ -z $ssh_hosts ]; then
|
||||
echo "ssh_hosts map not set"
|
||||
return
|
||||
fi
|
||||
|
||||
local actual_ssh=$(whence -p ssh)
|
||||
|
||||
function ssh() {
|
||||
if [ $# -lt 1 ]; then
|
||||
echo NO HOST
|
||||
return 1
|
||||
fi
|
||||
|
||||
local param=$1
|
||||
shift
|
||||
local host=$ssh_hosts[$param]
|
||||
|
||||
if [ -z "$host" ]; then
|
||||
echo INVALID HOST
|
||||
return 1
|
||||
fi
|
||||
|
||||
$actual_ssh $(echo $ssh_hosts[$param]) $* # $() to circumvent ssh from b0rking if options are present in map
|
||||
}
|
||||
|
||||
function _ssh() {
|
||||
for comp in ${(k)ssh_hosts}; do
|
||||
compadd $comp
|
||||
done
|
||||
}
|
||||
|
||||
compdef _ssh ssh
|
||||
Loading…
Add table
Add a link
Reference in a new issue