w3m-reddit 657 B

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. args=()
  3. until [ -z "$1" ]; do
  4. case "$1" in
  5. -t|--tmux) t=1; shift ;;
  6. --) shift ; break ;;
  7. -*) echo "invalid option $1" 1>&2 ; shift ;; # or, error and exit 1 just like getopt does
  8. *) args+=("$1") ; shift ;;
  9. esac
  10. done
  11. args+=("$@")
  12. for arg in "${args[@]}" ; do
  13. # Switch to mobile reddit
  14. url=${arg/http:\/\/reddit.com/http:\/\/m.reddit.com}
  15. url=${url/http:\/\/www.reddit.com/http:\/\/m.reddit.com}
  16. # Fix double backslash error in comment uri for mobile reddit
  17. url=${url/\/\/comments/\/comments}
  18. if [[ $t == "1" ]]; then
  19. tmux new-window 'w3m "'${url}'"'
  20. else
  21. w3m "${url}"
  22. fi
  23. done