Advertisement
Guest User

Untitled

a guest
Sep 1st, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.02 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #designed for firefox lol
  4. browser="/usr/bin/firefox"
  5.  
  6. #add user-defined site abbreviations here
  7. site=(
  8.     "g"
  9.     "y"
  10.     "aw"
  11.     "ap"
  12.     "aur"
  13.     "w"  
  14.     "wz"
  15. )
  16.  
  17. #add corresponding urls here
  18. url=(
  19.     "https://www.google.com/search?q="
  20.     "https://www.youtube.com/results?search_query="
  21.     "https://wiki.archlinux.org/index.php/"
  22.     "http://www.archlinux.org/packages/"
  23.     "http://aur.archlinux.org/packages.php?K="
  24.     "https://en.wikipedia.org/wiki/"
  25.     "https://zh.wikipedia.org/wiki/"
  26. )
  27.  
  28. function list(){
  29.     for((i=0; i < ${#site[@]}; i++)); do
  30.         echo "  "${site[i]}"    " ${url[i]}
  31.     done
  32. }
  33.  
  34. function usage(){
  35.     echo "Usage:"
  36.     echo "  "$(basename $0)" [o/to/wo][site abbreviation] [keyword]"
  37.     echo "  [o/to/wo]:  [open/tab-open/window-open]"
  38.     echo ""
  39.     echo "      -h  for help"
  40.     echo "      -l  to list only site abbrevations"
  41.     echo ""
  42.     echo "Site abbrevations:"
  43.     list
  44.     echo ""
  45.     echo "Examples:"
  46.     echo "  "$(basename $0)" og foo #google foo in current tab of firefox"
  47.     echo "  "$(basename $0)" toy foo    #search foo on youtube in a new tab"
  48.     echo "  "$(basename $0)" woy foo    #search foo on youtube in a new window"
  49.  
  50.     echo ""
  51.     echo "Troubleshooting:"
  52.     echo "  Q. Search page not opened in current tab?"
  53.     echo "  A. Open page \"about:config\" in firefox,"
  54.     echo "     and set browser.link.open_newwindow.override.external = 0"
  55.     echo ""
  56. }
  57.  
  58. function realmansearch(){
  59.     for((i=0; i < ${#site[@]}; i++)); do
  60.         if [ ${command} = ${site[i]} ]; then
  61.             ${browser} ${arg} "${url[i]}${keyword}"
  62.             break
  63.         fi          
  64.     done
  65.     if [ $i == ${#site[@]} ]; then
  66.         usage
  67.     fi
  68. }
  69.  
  70.  
  71.  
  72. keyword=$(echo $* | cut -d " " -f 2-)
  73. command=$1
  74.  
  75. if [[ $# < 1 ]]; then
  76.     usage
  77. elif [ ${command} = "-l" ]; then
  78.     list | cut -d " " -f 2-
  79. elif [[ $# < 2 ]]; then
  80.     usage
  81. elif [ ${command:0:1} = "o" ]; then
  82.     command=${command#o}
  83.     arg=""
  84.     realmansearch
  85. elif [ ${command:0:2} = "to" ]; then
  86.     command=${command#t*o}
  87.     arg="-new-tab"
  88.     realmansearch
  89. elif [ ${command:0:2} = "wo" ]; then
  90.     command=${command#w*o}
  91.     arg="-new-window"
  92.     realmansearch
  93. else
  94.     usage
  95. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement