#!/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