Dotfiles for my tiling window manager + terminal workflow.
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.

98 lines
3.0 KiB

  1. #!/bin/bash
  2. # Rick Astley in your Terminal.
  3. # By Serene Han and Justine Tunney <3
  4. version='1.1'
  5. rick='http://keroserene.net/lol'
  6. video="$rick/astley80.full.bz2"
  7. # TODO: I'll let someone with mac or windows machine send a pull request
  8. # to get gsm going again :)
  9. audio_gsm="$rick/roll.gsm"
  10. audio_raw="$rick/roll.s16"
  11. audpid=0
  12. NEVER_GONNA='curl -s -L http://bit.ly/10hA8iC | bash'
  13. MAKE_YOU_CRY="$HOME/.bashrc"
  14. red='\x1b[38;5;9m'
  15. yell='\x1b[38;5;216m'
  16. green='\x1b[38;5;10m'
  17. purp='\x1b[38;5;171m'
  18. echo -en '\x1b[s' # Save cursor.
  19. has?() { hash $1 2>/dev/null; }
  20. cleanup() { (( audpid > 1 )) && kill $audpid 2>/dev/null; }
  21. quit() { echo -e "\x1b[2J \x1b[0H ${purp}<3 \x1b[?25h \x1b[u \x1b[m"; }
  22. usage () {
  23. echo -en "${green}Rick Astley performs ♪ Never Gonna Give You Up ♪ on STDOUT."
  24. echo -e " ${purp}[v$version]"
  25. echo -e "${yell}Usage: ./astley.sh [OPTIONS...]"
  26. echo -e "${purp}OPTIONS : ${yell}"
  27. echo -e " help - Show this message."
  28. echo -e " inject - Append to ${purp}${USER}${yell}'s bashrc. (Recommended :D)"
  29. }
  30. for arg in "$@"; do
  31. if [[ "$arg" == "help"* || "$arg" == "-h"* || "$arg" == "--h"* ]]; then
  32. usage && exit
  33. elif [[ "$arg" == "inject" ]]; then
  34. echo -en "${red}[Inject] "
  35. echo $NEVER_GONNA >> $MAKE_YOU_CRY
  36. echo -e "${green}Appended to $MAKE_YOU_CRY. <3"
  37. echo -en "${yell}If you've astley overdosed, "
  38. echo -e "delete the line ${purp}\"$NEVER_GONNA\"${yell}."
  39. exit
  40. else
  41. echo -e "${red}Unrecognized option: \"$arg\""
  42. usage && exit
  43. fi
  44. done
  45. trap "cleanup" INT
  46. trap "quit" EXIT
  47. # Bean streamin' - agnostic to curl or wget availability.
  48. obtainium() {
  49. if has? curl; then curl -s $1
  50. elif has? wget; then wget -q -O - $1
  51. else echo "Cannot has internets. :(" && exit
  52. fi
  53. }
  54. echo -en "\x1b[?25l \x1b[2J \x1b[H" # Hide cursor, clear screen.
  55. #echo -e "${yell}Fetching audio..."
  56. if has? afplay; then
  57. # On Mac OS, if |afplay| available, pre-fetch compressed audio.
  58. [ -f /tmp/roll.s16 ] || obtainium $audio_raw >/tmp/roll.s16
  59. afplay /tmp/roll.s16 &
  60. elif has? aplay; then
  61. # On Linux, if |aplay| available, stream raw sound.
  62. obtainium $audio_raw | aplay -Dplug:default -q -f S16_LE -r 8000 &
  63. elif has? play; then
  64. # On Cygwin, if |play| is available (via sox), pre-fetch compressed audio.
  65. obtainium $audio_gsm >/tmp/roll.gsm.wav
  66. play -q /tmp/roll.gsm.wav &
  67. fi
  68. audpid=$!
  69. #echo -e "${yell}Fetching video..."
  70. # Sync FPS to reality as best as possible. Mac's freebsd version of date cannot
  71. # has nanoseconds so inject python. :/
  72. python <(cat <<EOF
  73. import sys
  74. import time
  75. fps = 25; time_per_frame = 1.0 / fps
  76. buf = ''; frame = 0; next_frame = 0
  77. begin = time.time()
  78. try:
  79. for i, line in enumerate(sys.stdin):
  80. if i % 32 == 0:
  81. frame += 1
  82. sys.stdout.write(buf); buf = ''
  83. elapsed = time.time() - begin
  84. repose = (frame * time_per_frame) - elapsed
  85. if repose > 0.0:
  86. time.sleep(repose)
  87. next_frame = elapsed / time_per_frame
  88. if frame >= next_frame:
  89. buf += line
  90. except KeyboardInterrupt:
  91. pass
  92. EOF
  93. ) < <(obtainium $video | bunzip2 -q 2> /dev/null)