mirror of
https://codeberg.org/hyperreal/bin
synced 2024-11-25 10:23:42 +01:00
Add charmssh
This commit is contained in:
parent
1bad5e0de6
commit
a2540ce77e
42
charmssh
Executable file
42
charmssh
Executable 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
|
Loading…
Reference in New Issue
Block a user