Samuel W. Flint 2 سال پیش
والد
کامیت
e94edb45eb
1فایلهای تغییر یافته به همراه32 افزوده شده و 6 حذف شده
  1. 32 6
      tmu

+ 32 - 6
tmu

@@ -4,7 +4,7 @@ TERMCMD=${TERMCMD:-urxvto}
 
 PROGNAME=$(basename $0)
 
-OPTSTRING="${PROGNAME} (-x) [ -h | -l | -z | -c name | -n name | -e name tab command ]"
+OPTSTRING="${PROGNAME} (-x) [ -h | -l | -L host | -z | -c name | -n name | -N host | -e name tab command ]"
 
 if [[ $# -eq 0 ]] ; then
     echo ${OPTSTRING} >&2
@@ -13,7 +13,7 @@ fi
 
 XWINFLAG=false
 
-while getopts "c:n:e:zlxh" OPT
+while getopts "c:n:e:L:N:zlxh" OPT
 do
     # shift
     case "$OPT" in
@@ -21,7 +21,7 @@ do
             XWINFLAG=true
             ;;
         z)
-            NAME=$(tmux list-sessions -F '#S' | grep term | sort -r | head -n 1)
+            NAME=$(tmux list-sessions -F '#S' | grep '^term' | sort -r | head -n 1)
             if [ -n "${NAME}" ] ; then
                 NUM=$(echo $NAME | cut -d- -f 2)
                 NUM=$(( NUM + 1 ))
@@ -43,6 +43,18 @@ do
                 [[ $NAME != "" ]] && ${TERMCMD} -e tmux attach -t $NAME
             fi
             ;;
+	L)
+	    if [[ $XWINFLAG != "true" ]] ; then
+		tmux list-sessions -F '#S' | grep "${OPTARG}"
+	    else
+		if [[ -e `which rofi` ]] ; then
+		    NAME=`tmux list-sessions -F '#S' | grep "${OPTARG}" | rofi -dmenu -p "screen session"`
+		else
+		    NAME=`tmux list-sessions -F '#S' | grep "${OPTARG}" | dmenu -p "screen session:"`
+		fi
+		[[ $NAME != "" ]] && ${TERMCMD} -e tmux attach -t $NAME
+	    fi
+	    ;;
         c)
             if [[ $XWINFLAG != "true" ]] ; then
                 tmux attach -t "${OPTARG}"
@@ -57,6 +69,18 @@ do
                 ${TERMCMD} -e tmu -n "${OPTARG}"
             fi
             ;;
+	N)
+	    
+	    NAME=$(tmux list-sessions -F '#S' | grep "^${OPTARG}" | sort -r | head -n 1)
+            if [ -n "${NAME}" ] ; then
+		NUM=$(echo $NAME | cut -d- -f 2)
+		NUM=$(( NUM + 1 ))
+		NAME="${OPTARG}-${NUM}"
+            else
+		NAME="${OPTARG}-0"
+            fi
+	    tmux new -s "${NAME}"
+	    ;;
         e)
             OPTIND1=$(( OPTIND + 1 ))
             TAB=${!OPTIND}
@@ -73,9 +97,11 @@ do
 -x            Turn on X-windows interaction.
 -z            Create a new, unnamed screen session with X Terminal.
 -l            List screen sessions (with -x, show in ROFI).
--c name       Connect (as an additional screen) to session "name".
--n name       Create and connect to a new screen session "name".
--e name tab command
+-l HOST       List sessions on HOST.
+-c NAME       Connect (as an additional screen) to session "name".
+-n NAME       Create and connect to a new screen session "name".
+-N HOST       Create and connect to a new numbered screen session for HOST.
+-e NAME TAB COMMAND
               Create a tab named "tab" running the command "command" in session "name".
 HELP
             exit