tmu 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. ${TERMCMD} -e tmux
  19. ;;
  20. l)
  21. if [[ $XWINFLAG != "true" ]] ; then
  22. tmux list-sessions -F '#S'
  23. else
  24. if [[ -e `which rofi` ]] ; then
  25. NAME=`tmux list-sessions -F '#S' | rofi -dmenu -p "screen session"`
  26. else
  27. NAME=`tmux list-sessions -F '#S' | dmenu -p "screen session:"`
  28. fi
  29. [[ $NAME != "" ]] && ${TERMCMD} -e tmux attach -t $NAME
  30. fi
  31. ;;
  32. c)
  33. if [[ $XWINFLAG != "true" ]] ; then
  34. tmux attach -t "${OPTARG}"
  35. else
  36. urxtvo -e "tmux attach -t \"${OPTARG}\""
  37. fi
  38. ;;
  39. n)
  40. if [[ $XWINFLAG != "true" ]] ; then
  41. tmux new -s "${OPTARG}"
  42. else
  43. ${TERMCMD} -e tmu -n "${OPTARG}"
  44. fi
  45. ;;
  46. e)
  47. OPTIND1=$(( OPTIND + 1 ))
  48. TAB=${!OPTIND}
  49. OPTIND1=$(( OPTIND + 1 ))
  50. COMMAND=${!OPTIND1}
  51. tmux new -s "${OPTARG}" -n "${TAB}" -d "${COMMAND}"
  52. exit
  53. ;;
  54. h)
  55. echo ${OPTSTRING} >&2
  56. cat <<HELP >&2
  57. -h Show this help.
  58. -x Turn on X-windows interaction.
  59. -z Create a new, unnamed screen session with X Terminal.
  60. -l List screen sessions (with -x, show in ROFI).
  61. -c name Connect (as an additional screen) to session "name".
  62. -n name Create and connect to a new screen session "name".
  63. -e name tab command
  64. Create a tab named "tab" running the command "command" in session "name".
  65. HELP
  66. exit
  67. ;;
  68. esac
  69. done