aboutsummaryrefslogtreecommitdiff
path: root/wtmux
diff options
context:
space:
mode:
Diffstat (limited to 'wtmux')
-rwxr-xr-xwtmux22
1 files changed, 15 insertions, 7 deletions
diff --git a/wtmux b/wtmux
index bef84c6..aa48386 100755
--- a/wtmux
+++ b/wtmux
@@ -1,3 +1,4 @@
+#!/usr/bin/env bash
#
# Worktemux: tmux session wrapper
# https://robots.thoughtbot.com/a-tmux-crash-course
@@ -12,17 +13,22 @@
# Default options.
opts=""
+name="$1"
+state="$2"
# Session selection.
-if [ ! -z "$1" ]; then
- if ! tmux list-sessions 2> /dev/null | grep -q "^$1:"; then
- session="new-session -d -s $1"
+if [ ! -z "${name}" ]; then
+ if ! tmux list-sessions 2> /dev/null | grep -q "^${name}:"; then
+ session="new-session -d -s ${name}"
- if [ "$1" = "root" ]; then
+ # Use a unique, per-session name
+ #session"${session} -t ${name}"
+
+ if [ "${name}" = "root" ]; then
sudo tmux attach
exit
- elif [ -f "$HOME/.tmux/$1" ]; then
- opts="$HOME/.tmux/$1"
+ elif [ -f "$HOME/.tmux/${name}" ]; then
+ opts="$HOME/.tmux/${name}"
elif [ -f "$HOME/.tmux/base" ]; then
opts="$HOME/.tmux/base"
else
@@ -37,7 +43,9 @@ if [ ! -z "$1" ]; then
fi
fi
- tmux attach -t $1
+ if [ -z "$state" ] || [ "$state" == "attached" ]; then
+ tmux attach -t ${name}
+ fi
else
tmux
fi