-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-picker
More file actions
executable file
·37 lines (30 loc) · 1.14 KB
/
ssh-picker
File metadata and controls
executable file
·37 lines (30 loc) · 1.14 KB
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
#!/bin/sh
# picker for launching SSH sessions to servers defined in $HOME/.ssh/config
SSH_CONFIG="$HOME/.ssh/config"
TERM="foot" # change me!
construct_list() {
HOSTS="$(awk '/^Host [^*]/ {print $2}' $SSH_CONFIG)"
for h in $HOSTS; do
HOSTNAME="$(awk -v host="$h" '
/^Host / { in_host = ($2 == host) }
in_host && /^[[:space:]]*HostName/ { print $2; exit }
/^Host / && $2 != host { in_host = 0 }
' $SSH_CONFIG)"
HOSTNAME="${HOSTNAME:-$h}"
SSH_USER="$(awk -v host="$h" '
/^Host / { in_host = ($2 == host) }
in_host && /^[[:space:]]*User/ { print $2; exit }
/^Host / && $2 != host { in_host = 0 }
' $SSH_CONFIG)"
SSH_USER="${SSH_USER:-$USER}" # default to logged in username
PORT="$(awk -v host="$h" '
/^Host / { in_host = ($2 == host) }
in_host && /^[[:space:]]*Port/ { print $2; exit }
/^Host / && $2 != host { in_host = 0 }
' $SSH_CONFIG)"
PORT="${PORT:-22}"
echo " $h ($SSH_USER@$HOSTNAME:$PORT)"
done
}
selection="$(printf "$(construct_list)" | fuzzel --dmenu --width=36 --prompt='Server: ' | awk '{print $2}')"
exec $TERM -e ssh "$selection"