scr 2.2 KB

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