mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
autocomplete hosts from hosts sections in ssh-config, two functions to load/unload keys from the agent (e.g. for use in .zshrc
This commit is contained in:
parent
f8f01262ab
commit
6bf97f3666
1 changed files with 39 additions and 0 deletions
39
plugins/ssh/ssh.plugin.zsh
Normal file
39
plugins/ssh/ssh.plugin.zsh
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
############################################################
|
||||
# Take all host sections in .ssh/config and offer them for
|
||||
# completion as hosts (e.g. for ssh, rsync, scp and the like)
|
||||
# Filter out wildcard host sections.
|
||||
local hosts
|
||||
if [[ -f $HOME/.ssh/config ]]; then
|
||||
hosts=($(cat $HOME/.ssh/config | egrep '^Host.*' | awk '{print $2}' | grep -v '^*' | sed -e 's/\.*\*$//' | grep '\.'))
|
||||
zstyle ':completion:*:hosts' hosts $hosts
|
||||
fi
|
||||
|
||||
############################################################
|
||||
# Remove host key from known hosts based on a host section
|
||||
# name from .ssh/config
|
||||
function ssh_rmhkey {
|
||||
if [[ "x$1" == "x" ]]; then return; fi
|
||||
ssh-keygen -R $(grep -A10 $1 ~/.ssh/config | grep -i HostName | head -n 1 | awk '{print $2}')
|
||||
}
|
||||
compctl -k hosts ssh_rmhkey
|
||||
|
||||
############################################################
|
||||
# Load SSH key into agent
|
||||
function ssh_load_key() {
|
||||
local key=$1
|
||||
if [[ "$key" == "" ]]; then return; fi
|
||||
if ( ! ssh-add -l | grep -q $key ); then
|
||||
ssh-add ~/.ssh/$key;
|
||||
fi
|
||||
}
|
||||
|
||||
############################################################
|
||||
# Remove SSH key from agent
|
||||
function ssh_unload_key {
|
||||
local key=$1
|
||||
if [[ "$key" == "" ]]; then return; fi
|
||||
if ( ssh-add -l|grep -q $key ); then
|
||||
local keyfile=$(ssh-add -l | grep $key | cut -d ' ' -f 3)
|
||||
ssh-add -d $keyfile
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue