From e984fb1dc5db0f3229f3732ec6021a801999dcac Mon Sep 17 00:00:00 2001 From: xero Date: Sun, 16 Nov 2014 16:46:44 -0500 Subject: tmux updates --- sys/code/sys/tmx | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 sys/code/sys/tmx (limited to 'sys') 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 -- cgit v1.2.1