0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【小ネタ】terminalからエラーメッセージをググる

Last updated at Posted at 2019-10-28

ターミナルで実行する際にエラーが出た時、ブラウザを起動して検索するプロセスでとても億劫になっていたのでターミナルから検索したい文字を入力すると自動でブラウザが開いて検索してくれるsomethingを作りました。
これでエラーが出たときに気負う事なく検索ができるようになります。
小ネタ程度のものなので、コピペして必ず動くとは言えないほどガバなコードです。
フローだけ参考にして、よかったら自作してみてください。

詳細

コマンドライン引数に検索したいワードを入力し、実行することで入力したワードを検索します。
検索結果は、ブラウザが起動して表示されます。
使用したブラウザは、safariです。
数行で書けます。

コード

search.py
import webbrowser, sys

url = 'https://www.google.com/search?client=safari&rls=en&q={}&ie=UTF-8&oe=UTF-8'
search = ' '.join(sys.argv[1:])
webbrowser.open_new_tab(url.format(search))

実行する際の、python search.py hoge の python search.pyを環境変数にします。

terminal
$ echo export google=python\ search.pyのフルパス >> ~/.bash_profile
$ source .bash_profile

これで簡単にターミナルから検索ができるようになりました。

terminal
$ $google hoge

感想

大したものではないですがこの程度のもので効率が上がるならええやん。と思いました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?