forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 49
/
.shellrc
31 lines (25 loc) · 633 Bytes
/
.shellrc
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
#!/bin/sh
if [[ -n "$SSH_TTY" ]]; then
_TERM=$CONFIG_TERM_SSH
else
_TERM=$CONFIG_TERM_LOCAL
fi
if [[ "$_TERM" == "screen" ]] && [[ ! "$TERMCAP" =~ .*screen.* ]]; then
screen -xR remote
exit
fi
if [[ "$_TERM" == "byobu" ]] && [[ -z "$BYOBU_BACKEND" ]]; then
byobu
exit
fi
if [[ "$_TERM" == "tmux" ]] && [[ -z "$TMUX" ]]; then
# get the id of a deattached session
TMUX_ID="`tmux ls 2> /dev/null | grep -v -m 1 attached | cut -d: -f 1`"
if [[ -z "$TMUX_ID" ]]; then
# if not available create a new one
tmux new-session
else
# if available attach to it
tmux attach-session -t "$TMUX_ID"
fi
fi