-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
iTermSshMenu.sh
executable file
·42 lines (34 loc) · 1.7 KB
/
iTermSshMenu.sh
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/bash
# <xbar.title>iTerm SSH Dropdown Menu</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Gerd Naschenweng</xbar.author>
# <xbar.author.github>magicdude4eva</xbar.author.github>
# <xbar.desc>Provides a simple menu of ssh hosts when clicked on opens a new ssh session in terminal</xbar.desc>
# <xbar.image>https://github-production-user-asset-6210df.s3.amazonaws.com/5545555/240065062-ea64630f-7545-49b1-93de-f917c7e88976.png</xbar.image>
# <xbar.dependencies></xbar.dependencies>
SSHFILE="$HOME/.ssh/config"
echo "💀 ssh | color=#ff0000"
echo "---"
#Enter list of servers below give it a name and an address
#After adding or changing refresh plugins
echo "Some Server | bash='$0' param1=ssh param2=root@127.0.0.1 terminal=false"
echo "---"
echo "All Servers"
awk '/^Host / && !/(\*)/ {print "--" $2" | bash='$0' param1=ssh param2="$2" terminal=false"}' $SSHFILE
echo "Amazon Servers"
awk '/^Host live_.*_amazon.com$/ && !/(\*)/ {print "--" $2" | bash='$0' param1=ssh param2="$2" terminal=false"}' $SSHFILE
echo "---"
echo "Synology | bash='$0' param1=ssh param2=root@192.168.1.97 terminal=false"
if [ "$1" = 'ssh' ]; then
if [ "$(osascript -e 'application "iTerm2" is running')" = "false" ]; then
osascript -e 'tell application "iTerm"' \
-e 'tell current session of current tab of current window to write text "ssh '$2'"' \
-e 'tell application "iTerm2" to activate' -e 'end tell'
else
osascript -e 'tell application "iTerm2"' \
-e 'tell current window to set newTab to (create tab with default profile)' \
-e 'tell current session of current tab of current window to write text "ssh '$2'"' \
-e 'tell application "iTerm2" to activate' -e 'end tell'
fi
exit
fi