Helper Function to Start New Tmux Session With the Name of Current Directory

There are many promising tools that helps with bootstrapping tmux sessions, but this simple function, originally shared by Chris Toomey from thoughtbot, beat them all :)

1
2
3
4
5
6
7
8
9
10
function tn() {

    if [ -z "$1" ]; then;
        session_name=$(basename `pwd`)
    else
        session_name=$1
    fi

    tmux new-session -s $session_name -n 'main'
}

Once added to ~/.zshrc or ~/.bashrc, etc., you can start new tmux session as simply as typing the following:

> tn

And it will take the name of current directory.

Enjoy!

Comments