summaryrefslogtreecommitdiff
path: root/scripts/ssh-terminal
blob: 99a240a790ce657050f14f6390281db3110b75d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh

# Prompts the user to select a known host from $HOME/.ssh/config,
# then connects to it via a configurable client (default: mosh) and
# executes a command on the server (default: tmux).
# Requires: dmenu (or similar), st (or other terminal), an ssh client

# Usage: ssh-terminal [-m menu] [-s ssh_client] [-e server_cmd]

menu="dmenu"
terminal="st"
ssh_client="mosh"
server_cmd="tmux"

usage() {
	echo "Usage: ssh-terminal [-m MENU] [-s SSH_CLIENT] [-e SERVER_CMD]"
}

while getopts "e:m:s:" opt; do
	case "$opt" in
		e)
			server_cmd="$OPTARG"
			;;
		m)
			menu="$OPTARG"
			;;
		s)
			ssh_client="$OPTARG"
			;;
		*)
			usage
			exit 1
			;;
	esac
done

selection=$(grep '^Host' $HOME/.ssh/config | awk '{print $2}' | sort | $menu)
if [ -n "$selection" ]; then
	echo "Executing: "
	echo $terminal "$ssh_client" "$selection" "$server_cmd"
	$terminal "$ssh_client" "$selection" "$server_cmd"
fi

Generated with cgit - Back to sebastiano.tronto.net