connect-screen 926 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/zsh -f
  2. if [[ $# -eq 0 ]] ; then
  3. echo "connect-screen [ screen-instance [ -x ] | list | dmenu ]"
  4. exit
  5. fi
  6. function open-screen {
  7. screen -r $1
  8. }
  9. function open-screen-x {
  10. xterm -e "screen -r $1"
  11. }
  12. function list-screen-sessions {
  13. screen -list | sed '$ d' | sed 1d | awk '{print $1}'
  14. }
  15. function with-external-completion {
  16. if [[ -e `which rofi` ]] ; then
  17. SCREEN=`list-screen-sessions | rofi -dmenu -p "screen session:"`
  18. [[ $SCREEN != "" ]] && open-screen-x $SCREEN
  19. else
  20. SCREEN=`list-screen-sessions | dmenu -p "screen session:"`
  21. [[ $SCREEN != "" ]] && open-screen-x $SCREEN
  22. fi
  23. }
  24. SCREEN=$1
  25. shift
  26. case ${SCREEN} in
  27. list)
  28. list-screen-sessions
  29. ;;
  30. dmenu)
  31. with-external-completion
  32. ;;
  33. *)
  34. if [[ $1 == "-x" ]] ; then
  35. open-screen-x $SCREEN
  36. else
  37. open-screen $SCREEN
  38. fi
  39. esac