3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tmuxアタッチスクリプト

Last updated at Posted at 2015-07-01

tmux を使っていて、気が付くとセッションが残っている事がある。
職場の踏み台サーバで「tmuxが4つも居ますよ」なんて言われると恥ずかしい。

そんなあなたに、むしろ私に、

tmux-attach.sh
#! /bin/sh
IFS='\n'
sessions=$(tmux list-sessions)
if [ $? -eq 0 ]
then
    numsessions=`echo $sessions | wc -l | sed -e 's/ //g'`
    echo numsessions: $numsessions
    if [ $numsessions -eq 1 ]
    then 
        echo $sessions
        echo attach
        exec tmux attach
    else
        echo there are $numsessions sessions found.
        echo which session do you want to attach ?
        echo $sessions
        read select
        exec tmux attach-session -t $select
    fi
else
    echo there are no sessions. start a new session.
    exec tmux
fi

セッションがあったらあったで、どれにする?って聞いてくれるので意図的に複数動かしても大丈夫。

あとは、ひとつのssh-agentでtmuxの中のシェル全部を賄う方法がほしい。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?