Add charmssh

This commit is contained in:
Jeffrey Serio 2023-06-21 11:46:54 -05:00
parent 1bad5e0de6
commit a2540ce77e

42
charmssh Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# This script uses Charm's Skate and Gum tools to select SSH hosts and connect
# to them.
# Check for gum and skate.
if ! test -x "$(command -v gum)"; then
echo "Missing dependency: gum"
echo "See github.com/charmbracelet/gum"
exit 1
fi
if ! test -x "$(command -v skate)"; then
echo "Missing dependency: skate"
echo "See github.com/charmbracelet/skate"
exit 1
fi
# Set CHARM_HOST
export CHARM_HOST="nexus.local"
# Select SSH host key from skate store with gum, get value with skate.
KEY=$(skate list -k | gum choose --limit=1)
if test -z "$KEY"; then
exit 0
fi
VALUE=$(skate get "$KEY")
# If VALUE contains non-standard SSH port, set PORT.
HOST=$(echo "$VALUE" | cut -d ":" -f 1)
if [[ "$VALUE" == *":"* ]]; then
PORT=$(echo "$VALUE" | cut -d ":" -f 2)
fi
# autossh into $HOST, using $PORT, if values are non-zero
if test -n "$PORT"; then
autossh -M 0 "$HOST" -p "$PORT" -X
else
autossh -M 0 "$HOST" -X
fi