screen-connect 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. if [[ $# -eq 0 ]] ; then
  3. echo "screen-connect [ -c (-N name) | -n (-N name) | -l | -? ] (-x)" >&2
  4. exit 1
  5. fi
  6. CONNECTFLAG=false
  7. NEWFLAG=false
  8. LISTFLAG=false
  9. XWINFLAG=false
  10. NAME=""
  11. while getopts "cnlxN:?" opt
  12. do
  13. case "$opt" in
  14. c)
  15. CONNECTFLAG=true
  16. ;;
  17. n)
  18. NEWFLAG=true
  19. ;;
  20. l)
  21. LISTFLAG=true
  22. ;;
  23. x)
  24. XWINFLAG=true
  25. ;;
  26. N)
  27. NAME="$OPTARG"
  28. ;;
  29. [?])
  30. echo "screen-connect [ -c (-N name) | -n (-N name) | -l | -? ] (-x)" >&2
  31. exit 1
  32. ;;
  33. esac
  34. done
  35. if [[ $CONNECTFLAG == "true" ]] ; then
  36. if [[ $NAME != "" ]] ; then
  37. if [[ $XWINFLAG != "true" ]] ; then
  38. exec screen -r $NAME
  39. else
  40. exec xterm -e "screen -r $NAME"
  41. fi
  42. fi
  43. elif [[ $NEWFLAG == "true" ]] ; then
  44. if [[ $NAME == "" ]] ; then
  45. if [[ $XWINFLAG != "true" ]] ; then
  46. exec screen
  47. else
  48. exec urxvto -class XTermScreen -e screen
  49. fi
  50. else
  51. if [[ $XWINFLAG != "true" ]] ; then
  52. exec screen -S $NAME
  53. else
  54. exec urxvto -class XTermScreen -e screen -S $NAME
  55. fi
  56. fi
  57. elif [[ $LISTFLAG == "true" ]] ; then
  58. if [[ $XWINFLAG != "true" ]] ; then
  59. screen -list | sed '$ d' | sed 1d | awk '{print $1}'
  60. else
  61. if [[ -e `which rofi` ]] ; then
  62. NAME=`screen -list | sed '$ d' | sed 1d | awk '{print $1}' | rofi -dmenu -p "screen session"`
  63. else
  64. NAME=`screen -list | sed '$ d' | sed 1d | awk '{print $1}' | dmenu -p "screen session:"`
  65. fi
  66. [[ $NAME != "" ]] && exec urxvto -class XTermScreen -e screen -r $NAME
  67. fi
  68. fi