I wrote up a script to handle sessions for me. I typically use ssh and a laptop so a multiplexer helps a lot, especially when updating software, encoding videos, or anything else that takes a lot of time. I haven't used tmux for very long, I just recently found it, so I don't know if there's any quirks I'm not covering in the script. Maybe other people can try it out and give suggestions?

#!/bin/sh

sessions=
# Check to see if tmux is running, or else sed might stall
tmux has-session 1>&2 2>/dev/null
if [ $? -eq 0 ]; then
        sessions=`tmux list-sessions 2>/dev/null | sed -e 's/^\(.*\): 
\(.*\)$/"\1" "\2" /' -e 's/(attached)/[attached]/' -e 's/(created.*)//' `
fi

# Get the terminal size, or default to 80x23 which is reasonable
ttysize=`stty size 2>/dev/null`
if [ $? -eq 0 ]; then
        ttyw=`echo $ttysize|cut -f2 -d\ `
        ttyh=`echo $ttysize|cut -f1 -d\ `
else
        ttyw=80
        ttyh=23
fi

# Clean up temp files when leaving
tmuxsm_rmf ()
{
        rm -f $tmpfile
}

trap tmuxsm_rmf exit

tmpfile=`mktemp -t tmuxsm`

eval dialog --menu \"tmux Session Manager\" \
        $(($ttyh - 4)) $(($ttyw - 9)) $(($ttyh - 11)) \
        "New" \"Start a new session\" \
        $sessions 2>$tmpfile

# User canceled, or something else happened
if [ $? -ne 0 ]; then
        echo "Canceled 1"
        exit 1
fi

result=`/bin/cat ${tmpfile}`
if [ "${result}" = "New" ]; then
        tmuxsm_rmf 
        dialog --inputbox "Session Name" 8  $(($ttyw - 9)) 2>$tmpfile
        # User canceled, or something else happened
        if [ $? -ne 0 ]; then
                exit 1
        fi
        result=`/bin/cat ${tmpfile}`
        exec tmux new-session -s "${result}"
else
        tmuxsm_rmf 
        exec tmux attach-session -t "${result}"
fi
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to