diff options
| author | Frank Dana <ferdnyc@gmail.com> | 2024-01-30 05:43:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-30 11:43:03 +0100 |
| commit | 8b2ce98578da743fbc4a208285f33744d6abd3cf (patch) | |
| tree | 1a51517ec476716437891e2be1a20707a27c8420 /plugins/ssh | |
| parent | 80c114cb3a64044ea50b623f96a35bc022db5e8d (diff) | |
| download | zsh-8b2ce98578da743fbc4a208285f33744d6abd3cf.tar.gz zsh-8b2ce98578da743fbc4a208285f33744d6abd3cf.tar.bz2 zsh-8b2ce98578da743fbc4a208285f33744d6abd3cf.zip | |
feat(ssh): add plugin (#12186)
Closes #2707
Co-authored-by: Frank Wittig <frank.wittig@here.com>
Co-authored-by: Frank Wittig <frank@e5k.com>
Diffstat (limited to 'plugins/ssh')
| -rw-r--r-- | plugins/ssh/ssh.plugin.zsh | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/ssh/ssh.plugin.zsh b/plugins/ssh/ssh.plugin.zsh new file mode 100644 index 000000000..085e71fa1 --- /dev/null +++ b/plugins/ssh/ssh.plugin.zsh @@ -0,0 +1,46 @@ +############################################################ +# 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. +_ssh_configfile="$HOME/.ssh/config" +if [[ -f "$_ssh_configfile" ]]; then + _hosts=($(egrep '^Host.*' "$_ssh_configfile" | awk '{print $2}' | grep -v '^*' | sed -e 's/\.*\*$//')) + zstyle ':completion:*:hosts' hosts $_hosts + unset _hosts +fi +unset _ssh_configfile + +############################################################ +# Remove host key from known hosts based on a host section +# name from .ssh/config +function ssh_rmhkey { + local ssh_configfile="$HOME/.ssh/config" + local ssh_host="$1" + if [[ -z "$ssh_host" ]]; then return; fi + ssh-keygen -R $(grep -A10 "$ssh_host" "$ssh_configfile" | 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 [[ -z "$key" ]]; then return; fi + local keyfile="$HOME/.ssh/$key" + local keysig=$(ssh-keygen -l -f "$keyfile") + if ( ! ssh-add -l | grep -q "$keysig" ); then + ssh-add "$keyfile" + fi +} + +############################################################ +# Remove SSH key from agent +function ssh_unload_key { + local key="$1" + if [[ -z "$key" ]]; then return; fi + local keyfile="$HOME/.ssh/$key" + local keysig=$(ssh-keygen -l -f "$keyfile") + if ( ssh-add -l | grep -q "$keysig" ); then + ssh-add -d "$keyfile" + fi +} |
