From e9f27a1f6c79fddabd5995a591a8398ca645c53f Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Thu, 20 Jun 2013 15:56:49 +0200 Subject: afssh: add interactive key selection using whiptail/dialog --- afssh | 46 +++++++++++++++++++++++++++++++++++----------- 1 file 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 -- cgit v1.2.3