mirror of
https://codeberg.org/hyperreal/bin
synced 2024-11-01 16:43:08 +01:00
40 lines
904 B
Plaintext
40 lines
904 B
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
# Check for gum
|
||
|
if ! test -x "$(command -v gum)"; then
|
||
|
echo "Missing dependency: gum"
|
||
|
echo "See github.com/charmbracelet/gum"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
SSH_CONFIG="${HOME}/.ssh/config"
|
||
|
usern_array=()
|
||
|
hostn_array=()
|
||
|
logins=()
|
||
|
|
||
|
while IFS= read -r line; do
|
||
|
if [[ "$line" == *"User"* ]]; then
|
||
|
usern=$(echo $line | awk '{ print $2 }')
|
||
|
usern_array+=($usern)
|
||
|
fi
|
||
|
done < "${SSH_CONFIG}"
|
||
|
|
||
|
while IFS= read -r line; do
|
||
|
if [[ "$line" == *"HostName"* ]]; then
|
||
|
hostn=$(echo $line | awk '{ print $2 }')
|
||
|
hostn_array+=($hostn)
|
||
|
fi
|
||
|
done < "${SSH_CONFIG}"
|
||
|
|
||
|
let "array_len = ${#usern_array[@]} - 1"
|
||
|
|
||
|
for i in $(seq 0 $array_len); do
|
||
|
userhost=$(printf "%s@%s" "${usern_array[i]}" "${hostn_array[i]}")
|
||
|
logins+=($userhost)
|
||
|
done
|
||
|
|
||
|
selection=$(printf "%s\n" "${logins[@]}" | gum choose --limit=1)
|
||
|
if test -n "${selection}"; then
|
||
|
ssh -X "${selection}"
|
||
|
fi
|