From 5553760f97821ba88fc9fe01771a2a7df6fd829a Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 20 Aug 2017 23:17:30 -0300 Subject: Full session support at wtmux --- wtmux | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'wtmux') diff --git a/wtmux b/wtmux index 5a3f2a8..4c6d336 100755 --- a/wtmux +++ b/wtmux @@ -2,30 +2,38 @@ # Worktemux: tmux session wrapper # https://robots.thoughtbot.com/a-tmux-crash-course # +# Alternatives: +# https://github.com/tmuxinator/tmuxinator +# https://github.com/tony/tmuxp # Default options. opts="" # Session selection. if [ ! -z "$1" ]; then - if tmux list-sessions 2> /dev/null | grep -q "^$1:"; then - tmux attach -t $1 - exit $? - else - session="new -s $1" - fi + if ! tmux list-sessions 2> /dev/null | grep -q "^$1:"; then + session="new-session -d -s $1" + + if [ "$1" = "root" ]; then + sudo tmux attach + exit + elif [ -f "$HOME/.tmux/$1" ]; then + opts="$HOME/.tmux/$1" + elif [ -f "$HOME/.tmux/base" ]; then + opts="$HOME/.tmux/base" + else + opts="" + fi - if [ "$1" == "root" ]; then - sudo tmux attach - exit - elif [ -f "$HOME/.tmux/$1" ]; then - opts="-f $HOME/.tmux/$1" - elif [ -f "$HOME/.tmux/base" ]; then - opts="-f $HOME/.tmux/base" - else - opts="" + # Start session. + if [ ! -z "$opts" ]; then + tmux $session \; source-file $opts + else + tmux $session + fi fi -fi -# Start session. -tmux $opts $session + tmux attach -t $1 +else + tmux +fi -- cgit v1.2.3