scr 2.1 KB

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