#!/usr/bin/env bash # # Worktemux: tmux session wrapper # https://robots.thoughtbot.com/a-tmux-crash-course # # Alternatives: # https://github.com/tmuxinator/tmuxinator # https://github.com/tony/tmuxp # https://github.com/tmux-plugins/tpm # https://github.com/tmux-plugins/tmux-resurrect # https://github.com/tmux-plugins/tmux-continuum # https://superuser.com/questions/440015/restore-tmux-session-after-reboot # Default options. opts="" name="$1" state="$2" # Session selection. if [ ! -z "${name}" ]; then if ! tmux list-sessions 2> /dev/null | grep -q "^${name}:"; then session="new-session -d -s ${name}" # Use a unique, per-session name #session"${session} -t ${name}" if [ "${name}" = "root" ]; then sudo tmux attach exit elif [ -f "$HOME/.tmux/${name}" ]; then opts="$HOME/.tmux/${name}" elif [ -f "$HOME/.tmux/base" ]; then opts="$HOME/.tmux/base" else opts="" fi # Start session. if [ ! -z "$opts" ]; then tmux $session \; source-file $opts else tmux $session fi fi if [ "$state" != "detached" ]; then tmux attach -t ${name} fi else tmux fi