From Sloppy Iguana, 3 Months ago, written in Plain Text.
  1. #!/bin/bash
  2. # Desc: Pipes! Sinks! Filters! Oh my! Is this a computer or a toilet?
  3. #       Recieving its name from Plan9 this script called a plumber.
  4. #       It plumbs the tangled garden hose Doug McIlroy left on the stairs.
  5. #       Parse URL based on regexpr and launch coresponding program.
  6. # Usage: plumber URL
  7.  
  8.  
  9. msg(){ printf -- "%s\n" "$@"; }
  10. emsg(){ printf -- "%s\n" "$@" >&2; }
  11. bail(){ emsg "$@"; usage; exit 1; }
  12. usage(){ awk -F '# ' 'NR>2{print $2};$0==""{exit}' <"$0"; }
  13. assert(){ [[ "$#" -ge "2" ]] || return -1; local type var t; ; eval "var=\$$#"; [[ -z "$var" ]] && return 1; ; for ((type=($#-1);type>0;type--)); do; eval "t=\$$type"; command awk -v t="^[[:$t:]]+\$" '$0!~t{exit 1}' <<<"$var" || return 1; done; }
  14. match(){ printf -- "%s\n" "$2" | awk -v m="$1" '$0~m{print $0}'; }
  15. idle(){ local freq __fdlock_idle; [[ ! -z "${__fdlock_idle:-}" ]] || exec {__fdlock_idle}<> <(:); read ${1:+-t "${1%[^0-9]*}"} -u "$__fdlock_idle" || :; exec <&"${__fdlock_idle}"-; }
  16.  
  17.  
  18.  
  19. pdf::(){
  20.   local pdf
  21.   pdf="$(mktemp -u)"
  22.   curl -sLo "$pdf" "$1"
  23.   xpdf -papercolor SlateGray -mattecolor grey18 -bg grey18 "$pdf"
  24. }
  25.  
  26. video::(){
  27.   notify-send "mpv: loading..." "$@"
  28.   /usr/bin/mpv --loop-playlist "$@"
  29. }
  30.  
  31. image::(){
  32.   local ft img
  33.   ft="$(file -i "$1")"
  34.   ft="${ft##*/}"
  35.   ft="${ft%%;*}"
  36.   img="$(mktemp -u).$ft"
  37.   curl -sLo "$img" "$1"
  38.   command viewnior "$img"
  39. }
  40.  
  41. www::(){
  42.   command nsgtk "$@"
  43. }
  44.  
  45. imgur(){
  46.   iget(){ curl -sL "$1" | awk -v RS="<meta" -F '"' '
  47.       $3~/content=/{
  48.         if($4~video) {while((getline)>0) {if($2~/^og:video$/)print $4} ret=4}
  49.         else {while((getline)>0) {if($2~/^og:image$/)print $4} ret=2}}
  50.       END{exit ret}'
  51.     return "$?"
  52.   }
  53.  
  54.   local u
  55.   u="$(iget "$1")"
  56.   [[ "$?" == "4" ]] && video:: "$u"; return
  57.   [[ "$?" == "2" ]] && www:: "$u"; return
  58. }
  59.  
  60.  
  61.  
  62. xclip -i <<<"$1"
  63.  
  64. case "$1" in
  65.   --help) usage; exit 0;;
  66.   *.webm) video:: "$1" ;;
  67.   *.pdf) pdf:: "$1" ;;
  68.   *://i.imgur.com/*|*://m.imgur.com/*) imgur "$1" ;;
  69.   *://imgur.com/*) imgur "$1"  ;;
  70.   *youtube.com/watch*|*youtube.com/playlist*|*youtu.be/*) video:: "$@" ;;
  71.   *) www:: "$1" ;;
  72. esac
captcha