tmu 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env bash
  2. TERMCMD=${TERMCMD:-urxvto}
  3. PROGNAME=$(basename $0)
  4. OPTSTRING="${PROGNAME} (-x) [ -h | -l | -z | -c name | -n name | -e name tab command ]"
  5. if [[ $# -eq 0 ]] ; then
  6. echo ${OPTSTRING} >&2
  7. exit 1
  8. fi
  9. XWINFLAG=false
  10. while getopts "c:n:e:zlxh" OPT
  11. do
  12. # shift
  13. case "$OPT" in
  14. x)
  15. XWINFLAG=true
  16. ;;
  17. z)
  18. NAME=$(tmux list-sessions -F '#S' | grep term | sort -r | head -n 1)
  19. if [ -n "${NAME}" ] ; then
  20. NUM=$(echo $NAME | cut -d- -f 2)
  21. NUM=$(( NUM + 1 ))
  22. NAME="term-${NUM}"
  23. else
  24. NAME=term-0
  25. fi
  26. ${TERMCMD} -e tmux new -s "${NAME}"
  27. ;;
  28. l)
  29. if [[ $XWINFLAG != "true" ]] ; then
  30. tmux list-sessions -F '#S'
  31. else
  32. if [[ -e `which rofi` ]] ; then
  33. NAME=`tmux list-sessions -F '#S' | rofi -dmenu -p "screen session"`
  34. else
  35. NAME=`tmux list-sessions -F '#S' | dmenu -p "screen session:"`
  36. fi
  37. [[ $NAME != "" ]] && ${TERMCMD} -e tmux attach -t $NAME
  38. fi
  39. ;;
  40. c)
  41. if [[ $XWINFLAG != "true" ]] ; then
  42. tmux attach -t "${OPTARG}"
  43. else
  44. urxtvo -e "tmux attach -t \"${OPTARG}\""
  45. fi
  46. ;;
  47. n)
  48. if [[ $XWINFLAG != "true" ]] ; then
  49. tmux new -s "${OPTARG}"
  50. else
  51. ${TERMCMD} -e tmu -n "${OPTARG}"
  52. fi
  53. ;;
  54. e)
  55. OPTIND1=$(( OPTIND + 1 ))
  56. TAB=${!OPTIND}
  57. OPTIND1=$(( OPTIND + 1 ))
  58. COMMAND=${!OPTIND1}
  59. tmux new -s "${OPTARG}" -n "${TAB}" -d "${COMMAND}"
  60. exit
  61. ;;
  62. h)
  63. echo ${OPTSTRING} >&2
  64. cat <<HELP >&2
  65. -h Show this help.
  66. -x Turn on X-windows interaction.
  67. -z Create a new, unnamed screen session with X Terminal.
  68. -l List screen sessions (with -x, show in ROFI).
  69. -c name Connect (as an additional screen) to session "name".
  70. -n name Create and connect to a new screen session "name".
  71. -e name tab command
  72. Create a tab named "tab" running the command "command" in session "name".
  73. HELP
  74. exit
  75. ;;
  76. esac
  77. done