config

My configuration files and custom scripts.
git clone https://git.tronto.net/config
Download | Log | Files | Refs

ssh-terminal (907B)


      1 #!/bin/sh
      2 
      3 # Prompts the user to select a known host from $HOME/.ssh/config,
      4 # then connects to it via a configurable client (default: mosh) and
      5 # executes a command on the server (default: tmux).
      6 # Requires: dmenu (or similar), st (or other terminal), an ssh client
      7 
      8 # Usage: ssh-terminal [-m menu] [-s ssh_client] [-e server_cmd]
      9 
     10 menu="dmenu"
     11 terminal="st"
     12 ssh_client="mosh"
     13 server_cmd="tmux"
     14 
     15 usage() {
     16 	echo "Usage: ssh-terminal [-m MENU] [-s SSH_CLIENT] [-e SERVER_CMD]"
     17 }
     18 
     19 while getopts "e:m:s:" opt; do
     20 	case "$opt" in
     21 		e)
     22 			server_cmd="$OPTARG"
     23 			;;
     24 		m)
     25 			menu="$OPTARG"
     26 			;;
     27 		s)
     28 			ssh_client="$OPTARG"
     29 			;;
     30 		*)
     31 			usage
     32 			exit 1
     33 			;;
     34 	esac
     35 done
     36 
     37 selection=$(grep '^Host' $HOME/.ssh/config | awk '{print $2}' | sort | $menu)
     38 if [ -n "$selection" ]; then
     39 	echo "Executing: "
     40 	echo $terminal "$ssh_client" "$selection" "$server_cmd"
     41 	$terminal "$ssh_client" "$selection" "$server_cmd"
     42 fi