Skip to content

Commit

Permalink
feat(tmux): add NEW session option to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-Rolf Gruen committed Nov 10, 2021
1 parent 98ff5fa commit b1d0933
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tmux/.tmuxrc
Expand Up @@ -49,18 +49,27 @@ tmuxmenu() {
INPUT=/tmp/tmux_in.$$
OUTPUT=/tmp/tmux_out.$$
#trap "rm $OUTPUT; rm $INPUT; exit" SIGHUP SIGINT SIGTERM

command tmux ls | nl | sed -r 's/^\s+([0-9]+)\s+([a-zA-Z0-9_-]+).*$/\1 \2/' > "${INPUT}"

echo "0 NEW" > "${INPUT}"
command tmux ls | nl | sed -r 's/^\s+([0-9]+)\s+([a-zA-Z0-9_-]+).*$/\1 \2/' >> "${INPUT}"

SESSION_LIST="$(cat $INPUT | tr '\n' ' ')"
COUNT="$(wc -l $INPUT | sed -r 's/^([0-9]+) .+$/\1/')"

command dialog --menu 'tmux session' 0 0 $COUNT $SESSION_LIST 2> "${OUTPUT}"

SESSION_ID="$(cat $OUTPUT)"
SESSION="$(grep -E "^$SESSION_ID " $INPUT | sed -r 's/^[0-9]+ (.+)$/\1/')"
if [[ $SESSION_ID -eq 0 ]]; then
echo "New session"
command dialog --inputbox 'session name' 0 0 2> "${OUTPUT}"
SESSION_NAME="$(cat $OUTPUT)"

command tmux attach -t $SESSION
command tmux new -s $SESSION_NAME
else
SESSION="$(grep -E "^$SESSION_ID " $INPUT | sed -r 's/^[0-9]+ (.+)$/\1/')"

command tmux attach -t $SESSION
fi
}

alias tmm='tmuxmenu'
Expand Down

0 comments on commit b1d0933

Please sign in to comment.