Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #designed for firefox lol
- browser="/usr/bin/firefox"
- #add user-defined site abbreviations here
- site=(
- "g"
- "y"
- "aw"
- "ap"
- "aur"
- "w"
- "wz"
- )
- #add corresponding urls here
- url=(
- "https://www.google.com/search?q="
- "https://www.youtube.com/results?search_query="
- "https://wiki.archlinux.org/index.php/"
- "http://www.archlinux.org/packages/"
- "http://aur.archlinux.org/packages.php?K="
- "https://en.wikipedia.org/wiki/"
- "https://zh.wikipedia.org/wiki/"
- )
- function list(){
- for((i=0; i < ${#site[@]}; i++)); do
- echo " "${site[i]}" " ${url[i]}
- done
- }
- function usage(){
- echo "Usage:"
- echo " "$(basename $0)" [o/to/wo][site abbreviation] [keyword]"
- echo " [o/to/wo]: [open/tab-open/window-open]"
- echo ""
- echo " -h for help"
- echo " -l to list only site abbrevations"
- echo ""
- echo "Site abbrevations:"
- list
- echo ""
- echo "Examples:"
- echo " "$(basename $0)" og foo #google foo in current tab of firefox"
- echo " "$(basename $0)" toy foo #search foo on youtube in a new tab"
- echo " "$(basename $0)" woy foo #search foo on youtube in a new window"
- echo ""
- echo "Troubleshooting:"
- echo " Q. Search page not opened in current tab?"
- echo " A. Open page \"about:config\" in firefox,"
- echo " and set browser.link.open_newwindow.override.external = 0"
- echo ""
- }
- function realmansearch(){
- for((i=0; i < ${#site[@]}; i++)); do
- if [ ${command} = ${site[i]} ]; then
- ${browser} ${arg} "${url[i]}${keyword}"
- break
- fi
- done
- if [ $i == ${#site[@]} ]; then
- usage
- fi
- }
- keyword=$(echo $* | cut -d " " -f 2-)
- command=$1
- if [[ $# < 1 ]]; then
- usage
- elif [ ${command} = "-l" ]; then
- list | cut -d " " -f 2-
- elif [[ $# < 2 ]]; then
- usage
- elif [ ${command:0:1} = "o" ]; then
- command=${command#o}
- arg=""
- realmansearch
- elif [ ${command:0:2} = "to" ]; then
- command=${command#t*o}
- arg="-new-tab"
- realmansearch
- elif [ ${command:0:2} = "wo" ]; then
- command=${command#w*o}
- arg="-new-window"
- realmansearch
- else
- usage
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement