aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2013-06-20 15:56:49 +0200
committerTimo Weingärtner <timo@tiwe.de>2013-06-20 15:56:49 +0200
commite9f27a1f6c79fddabd5995a591a8398ca645c53f (patch)
treef461b119d549aea5bf44e7650bf80fbae841e4f6
parent6064fef975a261aab7e92792c2a83687ae1fdb9e (diff)
downloadssh-agent-filter-e9f27a1f6c79fddabd5995a591a8398ca645c53f.tar.gz
afssh: add interactive key selection using whiptail/dialog
-rwxr-xr-xafssh46
1 files changed, 35 insertions, 11 deletions
diff --git a/afssh b/afssh
index 609e61f..2a4d570 100755
--- a/afssh
+++ b/afssh
@@ -23,7 +23,8 @@
set -e
usage () {
- echo "usage: afssh [ssh-agent-filter options] -- [ssh options]"
+ echo "normal usage: afssh [ssh-agent-filter options] -- [ssh arguments]"
+ echo "interactive: afssh -- [ssh arguments]"
echo
"$SAF" --help
echo
@@ -31,6 +32,18 @@ usage () {
exit
}
+interactive_selection () {
+ ssh-add -l | {
+ declare -a arr
+ while read size hash comment; do
+ arr+=("$hash" "$comment" "off")
+ done
+ "$DIALOG" --separate-output --title "afssh: key selection" --checklist "Which keys do you want to be forwarded?" 0 0 0 "${arr[@]}" 3>&1 1>&2 2>&3 3>&- | while read hash; do
+ printf '%s\n%s\n' "-f" "$hash"
+ done
+ }
+}
+
if ! ssh-add -l > /dev/null; then
echo "no keys in your ssh-agent or ssh-agent not running" >&2
exit 1
@@ -44,17 +57,28 @@ else
SAF=$(which ssh-agent-filter)
fi
-while true; do
- if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
- usage
- elif [ "$1" = "--" ]; then
- shift
- break
- else
- agent_filter_args+=("$1")
- shift
+if [ $# -le 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
+ usage
+elif [ "$1" = "--" ]; then
+ shift
+ if ! DIALOG=$(which whiptail) && ! DIALOG=$(which dialog); then
+ echo "neither whiptail nor dialog found in \$PATH, interactive mode doesn't work without one of them" >&2
+ exit 1
fi
-done
+ agent_filter_args=( $(interactive_selection) )
+else
+ while true; do
+ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
+ usage
+ elif [ "$1" = "--" ]; then
+ shift
+ break
+ else
+ agent_filter_args+=("$1")
+ shift
+ fi
+ done
+fi
# safeguard to not kill the real ssh-agent
unset SSH_AGENT_PID