This commit is contained in:
dongweiming 2013-07-25 23:49:53 -07:00
commit dc88eebd37

View file

@ -1,13 +1,31 @@
# web_search from terminal # web_search from terminal
# You can use the default browser to open the search, you can also choose to open
# the search browser, if you add in the parameter '-f' or '--firefox' will use firefox;
# Add the '-c' or '- chrome' will use of google-chrome
function web_search() { function web_search() {
# get the open command # get the open command
local open_cmd local open_cmd firefox chrome
for i in "$@"
do
if [[ $i =~ '(-f|--firefox)' ]];
then
firefox='true'
elif [[ $i =~ '(-c|--chrome)' ]];
then
chrome='true'
fi
done
if [[ $(uname -s) == 'Darwin' ]]; then if [[ $(uname -s) == 'Darwin' ]]; then
open_cmd='open' open_cmd='open'
[[ -n $firefox ]] && open_cmd='open -a "/Applications/Firefox.app"'
[[ -n $chrome ]] && open_cmd='open -a "/Applications/Google Chrome.app"'
else else
open_cmd='xdg-open' open_cmd='xdg-open'
[[ -n $firefox ]] && open_cmd='firefox'
[[ -n $chrome ]] && open_cmd='google-chrome'
fi fi
# check whether the search engine is supported # check whether the search engine is supported
@ -21,7 +39,7 @@ function web_search() {
# no keyword provided, simply open the search engine homepage # no keyword provided, simply open the search engine homepage
if [[ $# -le 1 ]]; then if [[ $# -le 1 ]]; then
$open_cmd "$url" eval $open_cmd "'$url'"
return return
fi fi
@ -29,13 +47,16 @@ function web_search() {
shift # shift out $1 shift # shift out $1
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
url="${url}$1+" if [[ ! $1 =~ '(-f|-c|--chrome|--firefox)' ]];
then
url="${url}$1+"
fi
shift shift
done done
url="${url%?}" # remove the last '+' url="${url%?}" # remove the last '+'
$open_cmd "$url" eval "$open_cmd" "'$url'"
} }
alias bing='web_search bing' alias bing='web_search bing'