Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.4 KiB

4 years ago
  1. #!/usr/bin/zsh
  2. count() {
  3. echo -n $1 | wc -c
  4. }
  5. dec() {
  6. echo "obase=10; ibase=16; $(echo "$1" | tr a-z A-Z)" | bc
  7. }
  8. hex() {
  9. echo "obase=16; ibase=10; $1" | bc
  10. }
  11. ulimit -n 5000
  12. colors() {
  13. color=1;
  14. count=0;
  15. space=" ";
  16. while [ $color -lt 256 ]; do
  17. if [[ $color == 10 ]]
  18. then
  19. space=" "
  20. fi
  21. if [[ $color == 100 ]]
  22. then
  23. space=" "
  24. fi
  25. echo -en "$color:$space\\033[38;5;${color}myeet\\033[48;5;${color}mworld\\033[0m"
  26. echo -n " "
  27. if [[ $count == 10 ]]
  28. then
  29. echo -en "\n";
  30. count=-1
  31. fi
  32. ((color++));
  33. ((count++))
  34. done
  35. echo ""
  36. }
  37. # TMATE Functions
  38. TMATE_PAIR_NAME="$(whoami)-pair"
  39. TMATE_SOCKET_LOCATION="/tmp/tmate-pair.sock"
  40. TMATE_TMUX_SESSION="/tmp/tmate-tmux-session"
  41. # Get current tmate connection url
  42. tmate-url() {
  43. url="$(tmate -S $TMATE_SOCKET_LOCATION display -p '#{tmate_ssh}')"
  44. echo "$url" | tr -d '\n' | xclip -selection clipboard
  45. echo "Copied tmate url for $TMATE_PAIR_NAME:"
  46. echo "$url"
  47. }
  48. # Start a new tmate pair session if one doesn't already exist
  49. # If creating a new session, the first argument can be an existing TMUX session to connect to automatically
  50. tmate-attach() {
  51. if [ -n "$1" ]; then
  52. echo "Attaching tmate to tmux session $1";
  53. echo $1 > $TMATE_TMUX_SESSION
  54. tmate -S "$TMATE_SOCKET_LOCATION" send -t "$TMATE_PAIR_NAME" "TMUX='' tmux attach-session -t $1; tmate-unpair" ENTER
  55. fi
  56. }
  57. tmate-pair() {
  58. if [ ! -e "$TMATE_SOCKET_LOCATION" ]; then
  59. tmate -S "$TMATE_SOCKET_LOCATION" -f "$HOME/.tmate.conf" new-session -d -s "$TMATE_PAIR_NAME"
  60. while [ -z "$url" ]; do
  61. url="$(tmate -S $TMATE_SOCKET_LOCATION display -p '#{tmate_ssh_ro}')"
  62. done
  63. echo "$url" | tr -d '\n' | xclip -selection clipboard
  64. echo "Copied tmate url for $TMATE_PAIR_NAME:"
  65. echo "$url"
  66. tmate -S "$TMATE_SOCKET_LOCATION" send -t "$TMATE_PAIR_NAME" "q" ENTER
  67. sleep 1
  68. #tmate-attach $1
  69. sleep 2
  70. fi
  71. tmate -S "$TMATE_SOCKET_LOCATION" attach-session -t "$TMATE_PAIR_NAME"
  72. }
  73. # Close the pair because security
  74. tmate-unpair() {
  75. if [ -e "$TMATE_SOCKET_LOCATION" ]; then
  76. if [ -e "$TMATE_SOCKET_LOCATION" ]; then
  77. tmux detach -s $(cat $TMATE_TMUX_SESSION)
  78. rm -f $TMATE_TMUX_SESSION
  79. fi
  80. tmate -S "$TMATE_SOCKET_LOCATION" kill-session -t "$TMATE_PAIR_NAME"
  81. echo "Killed session $TMATE_PAIR_NAME"
  82. else
  83. echo "Session already killed"
  84. fi
  85. }