aboutsummarylogtreecommitdiffstats
path: root/tmix.sh
diff options
context:
space:
mode:
authormyrrlyn2016-11-06 20:59:12 -0500
committermyrrlyn2016-11-06 21:01:56 -0500
commit77579fdf1506317b7b4542589b1788f118267084 (patch)
treeea79b539c9bb38d1e81cda57a34ae7cd21cdfac1 /tmix.sh
downloadaur-tmix.tar.gz
Package up the tmix script from the wiki
Diffstat (limited to 'tmix.sh')
-rw-r--r--tmix.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/tmix.sh b/tmix.sh
new file mode 100644
index 000000000000..7d99e483ce2f
--- /dev/null
+++ b/tmix.sh
@@ -0,0 +1,37 @@
+function tmix () {
+ trim () { echo $1; }
+
+# Permit running tmix, no arguments, as a shorthand for attaching to the user
+# session. `tmix self ...` also works.
+ if [[ -z "$1" || "$1" == "self" ]] ; then
+ tmux_base="$(whoami)"
+# Also permit using tmix for tmux ls. I and U are right next to each other after
+# all.
+ elif [[ "$1" == "ls" ]] ; then
+ pgrep tmux > /dev/null && tmux ls || echo "No tmux server running!"
+ exit 0
+ else
+ tmux_base="$1"
+ fi
+
+# Check if the specified base session is running, and if not, make it so.
+ tmux_nb=$(trim `tmux ls | grep "^${tmux_base}" | wc -l`)
+ if [[ "${tmux_nb}" == "0" ]] ; then
+ echo "Launching tmux base session ${tmux_base} ..."
+ tmux new-session -s "${tmux_base}" -d
+ fi
+# Don't attach to a tmux session from inside a tmux session. That's a recipe for
+# disaster.
+ if [[ ! -z "${TMUX}" ]] ; then
+ echo "Connecting to a tmux session from inside a tmux session is a BAD CALL"
+ exit 1
+ fi
+ echo "Launching copy of base session ${tmux_base} ..."
+ [[ ! -z "$2" ]] && tmux_sesh="$2" || tmux_sesh="$(date +%Y%m%d%H%M%S)"
+ tmux new-session -d -t "${tmux_base}" -s "${tmux_sesh}"
+# Spawn a new window, if the user asked for one.
+ if [[ "$3" ]] ; then
+ tmux new-window -n "$3"
+ fi
+ tmux attach-session -t "${tmux_sesh}" \; set-option destroy-unattached
+}