aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorxero <x@xero.nu>2014-11-16 16:46:44 -0500
committerxero <x@xero.nu>2014-11-16 16:46:44 -0500
commite984fb1dc5db0f3229f3732ec6021a801999dcac (patch)
tree8793e0c5abd93944a48c38669288bfe77a05f318 /sys
parent554812336d2a6a140cdec66ad587cf9e3b71d457 (diff)
downloaddotfiles_ascii-e984fb1dc5db0f3229f3732ec6021a801999dcac.tar.xz
dotfiles_ascii-e984fb1dc5db0f3229f3732ec6021a801999dcac.zip
tmux updates
Diffstat (limited to 'sys')
-rwxr-xr-xsys/code/sys/tmx45
1 files changed, 45 insertions, 0 deletions
diff --git a/sys/code/sys/tmx b/sys/code/sys/tmx
new file mode 100755
index 0000000..c912561
--- /dev/null
+++ b/sys/code/sys/tmx
@@ -0,0 +1,45 @@
+#
+# Modified TMUX start script from:
+# http://forums.gentoo.org/viewtopic-t-836006-start-0.html
+#
+# Store it to `~/bin/tmx` and issue `chmod +x`.
+#
+
+# Works because bash automatically trims by assigning to variables and by
+# passing arguments
+trim() { echo $1; }
+
+if [[ -z "$1" ]]; then
+ echo "Specify session name as the first argument"
+ exit
+fi
+
+# Only because I often issue `ls` to this script by accident
+if [[ "$1" == "ls" ]]; then
+ tmux ls
+ exit
+fi
+
+base_session="$1"
+# This actually works without the trim() on all systems except OSX
+tmux_nb=$(trim `tmux ls | grep "^$base_session" | wc -l`)
+if [[ "$tmux_nb" == "0" ]]; then
+ echo "Launching tmux base session $base_session ..."
+ tmux new-session -s $base_session
+else
+ # Make sure we are not already in a tmux session
+ if [[ -z "$TMUX" ]]; then
+ echo "Launching copy of base session $base_session ..."
+ # Session is is date and time to prevent conflict
+ session_id=`date +%Y%m%d%H%M%S`
+ # Create a new session (without attaching it) and link to base session
+ # to share windows
+ tmux new-session -d -t $base_session -s $session_id
+ if [[ "$2" == "1" ]]; then
+ # Create a new window in that session
+ tmux new-window
+ fi
+ # Attach to the new session & kill it once orphaned
+ tmux attach-session -t $session_id \; set-option destroy-unattached
+ fi
+fi