-
Notifications
You must be signed in to change notification settings - Fork 12
/
sssh2
executable file
·81 lines (74 loc) · 2.55 KB
/
sssh2
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Decription
# -----------
# Like [sssh](https://github.com/dmi3/bin/blob/master/sssh), in addition:
# * `hostname` parameter of [ssh command](https://manpage.me/?q=ssh) will appear in title.
# - Useful when calling by nickname from local `~/.ssh/config` i.e. `ssh server_nickname`, and change of server hostname is not an option.
# * If command supports tunneling, display it in title
# - I.e. `ssh -L 80:localhost:80 server_nickname` will set title `user@[80]server_nickname`
# - Avoid accidental closing of such tabs
# * Appends some useful [aliases](https://github.com/dmi3/fish/blob/master/aliases.fish) to existing `~/.bashrc`
# * Preserves command history on multiple sessions
#
# Usage
# -----
# See [sssh](https://github.com/dmi3/bin/blob/master/sssh)
get_first_non_option() {
SKIP_NEXT=false
for arg in "$@"; do
if [[ $arg == -* ]] ; then
SKIP_NEXT=true
elif [[ $arg == *:*:* ]] ; then
echo $arg | cut -d: -f1 | xargs -I "{}" printf "[{}]"
SKIP_NEXT=false
elif $SKIP_NEXT ; then
SKIP_NEXT=false
else
echo $arg; return 0
fi
done
}
NICKNAME=$(get_first_non_option "$@")
CUSTOM_TITLE="🖧 \$USER@$NICKNAME"
CUSTOM_PS1='$(tput bold)\]\[$(tput setaf 2)\][\u@'$NICKNAME' \w]\n🖧 \[$(tput sgr0)\]'
CUSTOM_RC="
alias sudo=\"sudo \"
alias ll=\"ls -lh\"
alias ff=\"find \$PWD -iname\"
alias mkdir=\"mkdir -pv\"
alias path=\"readlink -e\"
alias untar=\"tar -vxzf\"
alias sizeof=\"du -hs\"
alias fs=\"df -h -x squashfs -x tmpfs -x devtmpfs\"
alias myip=\"curl ifconfig.co\"
alias getmicro=\"curl https://getmic.ro | bash && sudo mv ./micro /usr/local/bin/\"
alias getsssh2=\"wget https://raw.githubusercontent.com/dmi3/bin/master/sssh2 && chmod +x sssh2 && sudo mv ./sssh2 /usr/local/bin/\"
alias micro=\"micro -mouse false \"
alias temp=\"watch sudo vcgencmd measure_temp\"
run() {
chmod +x \"\$1\"
exec \"./\$1\" &
}
mkcd () {
mkdir \"\$1\"
cd \"\$1\"
}
bak () {
cp \"\$1\" \"\$1.bak\"
}
shopt -s histappend
export HISTCONTROL=ignoreboth
export PROMPT_COMMAND=\"history -a; PS1=\\\"$CUSTOM_PS1\\\"\"
test -e /usr/share/doc/fzf/examples/key-bindings.bash && source /usr/share/doc/fzf/examples/key-bindings.bash
type sssh2 &> /dev/null && alias ssh=sssh2
echo -e \"\033]0;$CUSTOM_TITLE\a\"
"
PREV_TITLE=`xdotool getwindowfocus getwindowname`
echo -e "\033]0;$NICKNAME\a"
/usr/bin/ssh -t "$@" "
SSSH_RC=\$(mktemp)
cp ~/.bashrc \$SSSH_RC
echo '$CUSTOM_RC' >> \$SSSH_RC
bash --rcfile \$SSSH_RC
rm \$SSSH_RC"
echo -e "\033]0;$PREV_TITLE\a"