shitchell

tt

Aug 11th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. SESSION_DIR="$HOME/.tmux/sessions/"
  4. SESSION_NAME="$1"
  5. DEFAULT_SESSION="main"
  6.  
  7. if [[ -z "$SESSION_NAME" ]]; then
  8.     if [[ -n "$DEFAULT_SESSION" ]]; then
  9.         SESSION_NAME="$DEFAULT_SESSION"
  10.     fi
  11. fi
  12.  
  13. # Determine if the session exists
  14. EXISTS=$(tmux ls | cut -d ':' -f 1 | grep "^$SESSION_NAME$")
  15.  
  16. if [[ -n "$EXISTS" ]]; then
  17.     if [[ -n "$TMUX" ]]; then
  18.         TMUX="" tmux switch-client -t $SESSION_NAME
  19.     else
  20.         tmux attach-session -t $SESSION_NAME
  21.     fi
  22. else
  23.     # Determine if a config file exists
  24.     if [[ -f "$SESSION_DIR/$SESSION_NAME" ]]; then
  25.         source $SESSION_DIR/$SESSION_NAME
  26.     else
  27.         TMUX= tmux new-session -d -s $SESSION_NAME
  28.         if [[ -n "$TMUX" ]]; then
  29.             TMUX= tmux switch-client -t $SESSION_NAME
  30.         else
  31.             tmux attach-session -t $SESSION_NAME
  32.         fi
  33.     fi
  34. fi
Add Comment
Please, Sign In to add comment