Add gumssh

This commit is contained in:
Jeffrey Serio 2022-12-14 22:47:24 -06:00
parent 83f24d5ff3
commit 227d478031
2 changed files with 39 additions and 8 deletions

8
emacs
View File

@ -1,8 +0,0 @@
#!/bin/sh
# distrobox_binary
# name: "default0"
if [ ! -f /run/.containerenv ] && [ ! -f /.dockerenv ]; then
/usr/local/bin/distrobox-enter -n "default0" -- /bin/emacs $@
else
/bin/emacs $@
fi

39
gumssh Executable file
View File

@ -0,0 +1,39 @@
#!/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