Created
October 23, 2012 01:03
-
-
Save yonchu/3936037 to your computer and use it in GitHub Desktop.
コマンドラインからGoogle検索するスクリプト(主にMac用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Goolge検索 | |
# | |
# .bashrc or .zshrc などに設定してご使用する | |
# もしくは関数の中身を独立したスクリプトにして使用する | |
# | |
# e.g. | |
# $ google <keyword> | |
# | |
google() { | |
local str opt | |
local open_cmd | |
local google_url='http://www.google.co.jp' | |
if [ $# != 0 ]; then | |
for i in $*; do | |
# 検索ワードを+記号でつなぐ(and検索) | |
# URLエンコード | |
#$i=$(echo "$i" | nkf -wMQ | tr = %) | |
str="$str${str:++}$i" | |
done | |
opt='search?num=100&hl=ja&lr=lang_ja' | |
opt="${opt}&q=${str}" | |
fi | |
case "${OSTYPE}" in | |
darwin*) | |
open_cmd='open' | |
;; | |
linux*) | |
if type w3m >/dev/null 2>&1; then | |
open_cmd='w3m' | |
fi | |
;; | |
esac | |
if [ -z "$open_cmd" ]; then | |
echo "error: command for open is not found" 2>&1 | |
return 1 | |
fi | |
$open_cmd "$google_url"/$opt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment