Skip to content

Instantly share code, notes, and snippets.

@ericgj
Last active May 23, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericgj/e9ff374bb7ec4378afa94b8eaed16443 to your computer and use it in GitHub Desktop.
Save ericgj/e9ff374bb7ec4378afa94b8eaed16443 to your computer and use it in GitHub Desktop.
tmux open session/window for project
#!/usr/bin/env sh
# loosely based on http://pastebin/D8y7prYV, except with windows not sessions
if [ ${#} -eq 3 ]; then
echo "You need to provide both a session and path" 2>&1
exit 1
fi
sess=${1}
cd "${2}" # note with CDPATH, the passed path may be a shortcut. So we cd first.
name=$(basename $PWD)
if tmux list-windows -t "${sess}" -F "#W" | grep "^${name}\$" 2>&1 > /dev/null; then
tmux attach-session -d -t "${sess}" \; select-window -t "$name"
else
tmux attach-session -t "${sess}" \; new-window -c "$PWD" -n "$name"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment