From 227d4780317160cb1ea3560a5da93b60ccb47d41 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Wed, 14 Dec 2022 22:47:24 -0600 Subject: [PATCH] Add gumssh --- emacs | 8 -------- gumssh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) delete mode 100755 emacs create mode 100755 gumssh diff --git a/emacs b/emacs deleted file mode 100755 index 0b9a286..0000000 --- a/emacs +++ /dev/null @@ -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 diff --git a/gumssh b/gumssh new file mode 100755 index 0000000..24451a7 --- /dev/null +++ b/gumssh @@ -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