-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·32 lines (30 loc) · 929 Bytes
/
start.sh
File metadata and controls
executable file
·32 lines (30 loc) · 929 Bytes
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
#!/bin/bash
PATH=/usr/local/bin:$PATH
if ! which fzf &>/dev/null; then
echo "Please install fzf first"
exit 1
fi
hosts=`cat ~/.ssh/known_hosts | tr ',' ' ' | awk '{gsub(/\]|\[/,"",$1); print $1}' | sort -u | fzf -m --reverse --print-query --exact --no-mouse`
if [ $? -gt 1 ]; then exec bash --login; fi # ESC pressed - local session
q=`echo "$hosts" | head -1`
c=`echo "$hosts" | tail -n +2`
# empty choice, try query
if [ -n "$q" -a -z "$c" ]; then
ssh "$q"
# single choice
elif [ `echo "$c" | wc -l` == 1 ]; then
h=`echo "$c" | cut -d. -f1`
echo -ne "\033]1;$h\a"
if echo "$c" | grep -q :; then
h=`echo "$c" | cut -d: -f1`
p=`echo "$c" | cut -d: -f2`
ssh -p $p $h
else
ssh "$c"
fi
# multichoice
else
python=`ls /Users/aryabov/Library/ApplicationSupport/iTerm2/iterm2env/versions/*/bin/python | cut -d' ' -f1`
dir=`dirname "${BASH_SOURCE[0]}"`
$python "$dir"/i2cssh.py $c || sleep 60
fi