Created
September 29, 2013 11:26
-
-
Save piger/6751638 to your computer and use it in GitHub Desktop.
zsh script for ssh key management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# portachiavi.zsh | |
# Dialog script for ssh key management. | |
# by: Daniel Kertesz <[email protected]> on 03-03-2008 | |
SSHOPTS="-c" | |
: ${DIALOG=dialog} | |
setopt extendedglob | |
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$ | |
trap "rm -f $tempfile" 0 1 2 5 15 | |
the_dialog () { | |
keys=() | |
foreach key ($HOME/.ssh/*.pub(:r)); do | |
if ! ssh-add -l | grep -w $key > /dev/null; then | |
keys=($keys[@] $key:t $key) | |
fi | |
done | |
if [[ -z $keys ]]; then | |
echo "No more keys in keychain ($HOME/.ssh/*.pub)" | |
exit | |
fi | |
$DIALOG --title "Portachiavi" --cancel-label "Quit" \ | |
--menu "Choose the key you want to load on the agent\n" \ | |
20 51 4 $keys[@] 2> $tempfile | |
retval=$? | |
choice=`cat $tempfile` | |
case $retval in | |
0) | |
clear | |
ssh-add $SSHOPTS $HOME/.ssh/$choice | |
the_dialog | |
;; | |
1) | |
clear | |
echo "Goodbye!";; | |
255) | |
clear | |
echo "Goodbye!";; | |
esac | |
} | |
the_dialog | |
# vim: ft=zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment