Last active
December 28, 2021 11:33
-
-
Save ErebusBat/dacc0bcd92d7aa1494f1 to your computer and use it in GitHub Desktop.
tmux login shell script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See http://www.erebusbat.com/2015/08/tmux-login-wrapper-script/ | |
# Inspired by https://github.com/nicknisi/dotfiles | |
# abort if we're already inside a TMUX session | |
[ "$TMUX" == "" ] || exit 0 | |
export SHELL=/usr/local/bin/zsh | |
export TERM=xterm-256color | |
export PATH=/usr/local/bin:$PATH | |
export COLUMNS=1 | |
function printLineSep() { | |
clear | |
echo -e "\n===============================================" | |
} | |
function newSession() { | |
NEWK="==== NEW TMUX SESSION" | |
PS3="Create new TMUX Session: " | |
tmuxinator_dir=$HOME/.tmuxinator | |
# Remove the directory, make it prettier | |
sessions=$(ls ${tmuxinator_dir}/*.yml | rev | cut -d '/' -f1 | rev | cut -d '.' -f1) | |
options=("$NEWK" $sessions) | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
$NEWK) | |
read -p "Enter new session name: " SESSION_NAME | |
printLineSep | |
tmux new -s "$SESSION_NAME" | |
break | |
;; | |
*) | |
# Load RVM | |
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then | |
source "$HOME/.rvm/scripts/rvm" | |
fi | |
echo "Found mux: $(which mux)" | |
printLineSep | |
mux $opt | |
break | |
;; | |
esac | |
done | |
} | |
function mainMenu() { | |
# present menu for user to choose which workspace to open | |
PS3="Please choose your session: " | |
NEWK="==== NEW SESSION" | |
RAWK="==== RAW ZSH (no tmux)" | |
options=("$NEWK" $(tmux list-sessions -F "#S") "$RAWK") | |
echo -e "\n\n" | |
echo "Available sessions" | |
echo "------------------" | |
echo " " | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
$NEWK) | |
# read -p "Enter new session name: " SESSION_NAME | |
# tmux new -s "$SESSION_NAME" | |
printLineSep | |
newSession | |
break | |
;; | |
$RAWK) | |
zsh --login | |
break;; | |
*) | |
printLineSep | |
tmux attach-session -t $opt | |
break | |
;; | |
esac | |
done | |
} | |
# Show a looping menu as long as there are tmux sessions active (or it is the first run) | |
SHOWMENU=1 | |
while [ "$SHOWMENU" == "1" ]; do | |
SHOWMENU=0 | |
mainMenu | |
# Check to see if we still have sessions, if we do, then let them choose again | |
if [[ ! -z "$(tmux list-sessions)" ]]; then | |
SHOWMENU=1 | |
echo "Previous session ended, select new session (or CTRL-C)" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!