diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2019-10-15 20:56:41 -0400 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2019-10-15 20:56:41 -0400 |
| commit | eefbd029b55b2782b0d7b11b4989ce0ca9b256cd (patch) | |
| tree | 535511fd3154342117d67171e28a312bd30c7f87 /tmux/tmx.sh | |
| parent | 5840f413825e053b645a338d71c1916a06094335 (diff) | |
| download | dotfiles-eefbd029b55b2782b0d7b11b4989ce0ca9b256cd.tar.gz dotfiles-eefbd029b55b2782b0d7b11b4989ce0ca9b256cd.tar.xz | |
Massive organization of my dotfiles
Diffstat (limited to 'tmux/tmx.sh')
| -rw-r--r-- | tmux/tmx.sh | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tmux/tmx.sh b/tmux/tmx.sh new file mode 100644 index 0000000..0d66c27 --- /dev/null +++ b/tmux/tmx.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# Modified further by Mitchell Riedstra to be compatible with /bin/sh + +# +# 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 + # Kill defunct sessions first + old_sessions=$(tmux ls 2>/dev/null | egrep "^[0-9]{14}.*[0-9]+\)$" | cut -f 1 -d:) + for old_session_id in $old_sessions; do + tmux kill-session -t $old_session_id + done + + 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 + # Create a new window in that session + #tmux new-window + # Attach to the new session + tmux attach-session -t $session_id + # When we detach from it, kill the session + tmux kill-session -t $session_id + fi +fi |
