Skip to content

Instantly share code, notes, and snippets.

@schoblaska
Last active January 9, 2018 16:38
Show Gist options
  • Save schoblaska/4f923da5e395d1815e2819e200724910 to your computer and use it in GitHub Desktop.
Save schoblaska/4f923da5e395d1815e2819e200724910 to your computer and use it in GitHub Desktop.
Bash script to either create or attach to a named tmux session with the given working directory.
#!/bin/bash
if [ "$1" != "" ]; then
cd $1
fi
DIR_NAME=${PWD##*/}
tmux has-session -t $DIR_NAME 2>/dev/null
if [ $? -eq 1 ]
then
tmux new -s $DIR_NAME
else
tmux attach -t $DIR_NAME
fi
@schoblaska
Copy link
Author

schoblaska commented Jan 9, 2018

Eg: tm ~/projects/myapp will create a new tmux session in that directory with the name myapp, or attach to one if it already exists. tm with no arguments will do the same but for the current directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment