torchooser 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # Torchooser is a hack to start TOT-Browser with a chosen URL. A list comes from a file named urls.
  3. # Probably doesn't work anymore...
  4. # If stdin is not a tty, start it in a terminal - unix.stackexchange.com/a/26691
  5. if ! [ -t 0 ]; then
  6. term="${XTERMINAL-xterm}"
  7. case "$term" in
  8. xterm)
  9. "$term" -sh 1.3 -geometry 70x24 -T "${0##*/}" -e bash -c "$0 \"$@\"" "$@"
  10. ;;
  11. zutty)
  12. "$term" -geometry 70x24 -title "${0##*/}" -e bash -c "$0 \"$@\"" "$@"
  13. ;;
  14. *)
  15. "$term" -geometry 70x24 -T "${0##*/}" -e bash -c "$0 \"$@\"" "$@"
  16. ;;
  17. esac
  18. fi
  19. # if we have a command line argument, and it is "-x", then get content of clipboard
  20. # otherwise use it as is...
  21. [ -n "$1" ] && { [[ "$1" == "-x" ]] && str="$(xclip -o)" || str="$1"; }
  22. # ... but only the 1st line
  23. str="${str%%$'\n'*}"
  24. torstart() {
  25. [ -z "$1" ] && return
  26. cd "$HOME/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/"
  27. ./start-tor-browser.desktop "$1"
  28. }
  29. array=()
  30. helpy=()
  31. if [ -n "$str" ]; then
  32. if [ -r "$str" ]; then
  33. mapfile -t array < "$str"
  34. else
  35. #~ while read line; do break; done <<<"$1"
  36. array=( "$str" "https://duckduckgo.com/?q=$str" "https://thepiratebay.org/search.php?video=on&q=$str" ) # only read until first newline
  37. fi
  38. fi
  39. for file in "$(dirname "$0")/urls" "$XDG_CONFIG_HOME/tor/urls"; do
  40. [ -r "$file" ] && mapfile -t helpy < "$file"
  41. done
  42. array=( "${array[@]}" "${helpy[@]}" )
  43. # array with 2 colors and reset to normal
  44. helpy=( "" "" "(B" )
  45. # intersperse list with alternating colors
  46. for ((i=0;i<${#array[@]};i++)); do ((i==${#array[@]}-1)) && array[i]="${array[i]}${helpy[2]}" || array[i]="${array[i]}${helpy[$((i%2))]}"; done
  47. PS3="Choice: "
  48. # Start with the 2nd color
  49. printf '%s' "${helpy[1]}"
  50. select url in "${array[@]}"; do
  51. # Remove escape sequences from back of Url:
  52. for i in "${helpy[@]}"; do url="${url%$i}"; done
  53. torstart "$url"
  54. done