方法1:
if [ "$TERM" != "screen" ]; then
WHOAMI=$(whoami)
if tmux has-session -t $WHOAMI 2>/dev/null; then
tmux -2 attach-session -t $WHOAMI
else
tmux -2 new-session -s $WHOAMI
exit
fi
fi
方法2:
if [ `which tmux 2> /dev/null` -a -z "$TMUX" ]; then
tmux -2 attach || tmux -2 new; exit
fi
20220315更新:
[ -f /usr/bin/tmux ] && [ -z "$TMUX" ] && { tmux attach || tmux new-session;}
20230211更新,更简单的方法:
tmux new -As0
参考:
http://bionicraptor.ca/2011/07/24/automatically-start-tmux/
https://coderwall.com/p/tgm2la
标签:tmux