Skip to content

Instantly share code, notes, and snippets.

@abcang
Created April 9, 2016 10:33
Show Gist options
  • Save abcang/11bfcff22a0633600aefbb01550b8e38 to your computer and use it in GitHub Desktop.
Save abcang/11bfcff22a0633600aefbb01550b8e38 to your computer and use it in GitHub Desktop.
ssh先の場合tmux自動起動するやつ。.zshrcとかに入れると便利。tmuxをデタッチするとssh終了するか聞かれるので便利
## ssh先の場合tmux自動起動
if [[ -n "${REMOTEHOST}${SSH_CONNECTION}" && -z "$TMUX" && -z "$STY" ]] && type tmux >/dev/null 2>&1; then
function confirm {
MSG=$1
while :
do
echo -n "${MSG} [Y/N]: "
read ans
case $ans in
[yY]) return 0 ;;
[nN]) return 1 ;;
esac
done
}
option=""
if tmux has-session && tmux list-sessions; then
option="attach"
fi
tmux $option && confirm "exit?" && exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment