0
0

terminal_launch.zsh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/zsh
  2. while true; do
  3. tput civis;
  4. items=("zsh" "alpha")
  5. items+=("${(@f)$(tmux list-sessions -F '#S' 2> /dev/null | grep -v '^alpha$' | cat - <(echo 'beta\ngamma') | uniq | head -n 2)}")
  6. items+=("${(z)$($DOTFILES_DIR/.scripts/ssh_launch.zsh 2)}")
  7. printf "\r\n"
  8. printf " Welcome to \e[31m${TERM}\e[0m, \e[33m${USER}\e[0m@\e[33m${HOST}\e[0m.\n"
  9. printf "\n"
  10. printf " a) Open a \e[36mlocal\e[0m \e[4m${items[1]}\e[0m shell.\n"
  11. printf " r) \e[3m(Default)\e[0m Attach the \e[33m${items[2]}\e[0m \e[4mtmux\e[0m session.\n"
  12. printf " s) Attach the \e[33m${items[3]}\e[0m \e[4mtmux\e[0m session.\n"
  13. printf " t) Attach the \e[33m${items[4]}\e[0m \e[4mtmux\e[0m session.\n"
  14. printf " n) Start an \e[4mssh\e[0m session for \e[31m${items[5]}\e[0m.\n"
  15. printf " e) Start an \e[4mssh\e[0m session for \e[31m${items[6]}\e[0m.\n"
  16. printf " i) \e[33mSelect\e[0m a \e[4mtmux\e[0m session.\n"
  17. printf " o) \e[31mSelect\e[0m an \e[4mssh\e[0m session.\n"
  18. printf "\n"
  19. for countdown in 10 9 8 7 6 5 4 3 2 1; do
  20. for dots in 0 1 2 3 4 5; do
  21. if [[ -z "$selection" ]]; then
  22. printf "\r Defaulting to \e[4mtmux\e[0m \e[33m${items[2]}\e[0m in ${countdown}";
  23. for dotprint in 0 1 2 3 4 5; do
  24. if (( $dots > dotprint )); then
  25. printf "."
  26. else
  27. printf " "
  28. fi;
  29. done;
  30. read -k1 -s -t 0.2 selection
  31. fi
  32. done;
  33. done;
  34. clear;
  35. tput cnorm;
  36. case $selection in
  37. a)
  38. /bin/zsh
  39. ;;
  40. r|"")
  41. tmux new-session -A -s ${items[2]} "timeout 60s /bin/zsh $DOTFILES_DIR/.scripts/project_launch.zsh"
  42. ;;
  43. s)
  44. tmux new-session -A -s ${items[3]}
  45. ;;
  46. t)
  47. tmux new-session -A -s ${items[4]}
  48. ;;
  49. n)
  50. /bin/zsh -c "$DOTFILES_DIR/.scripts/ssh_launch.zsh ${items[5]}"
  51. ;;
  52. e)
  53. /bin/zsh -c "$DOTFILES_DIR/.scripts/ssh_launch.zsh ${items[6]}"
  54. ;;
  55. i)
  56. # It's hard to know if we're is already in a tmux pane; but, if the
  57. # `choose-tree` command fails instantly, then we're probably not!
  58. starttime=$(date +%s);
  59. tmux choose-tree;
  60. if [ $starttime -eq $(date +%s) ]; then
  61. tmux new-session -A -s ${items[2]}\; choose-tree;
  62. fi
  63. ;;
  64. o)
  65. /bin/zsh -c $DOTFILES_DIR/.scripts/ssh_launch.zsh
  66. ;;
  67. esac;
  68. selection=""
  69. clear;
  70. done;