GitHub のコミットメッセージを CLI から検索できる gommit-m がとても便利。
commit-m: GitHubコミットメッセージの文例が検索できるサービス がとても便利なのだけど、CLI からも検索できるようにした gommit-m がとても便利だったのでメモ。
gommit-m の使い方
gommit-m 検索ワード
で検索ワードを含むリポジトリとコミットメッセージを表にして出力してくれる。
$ gommit-m japanese Search Result : 103 results : 1/4 pages url: http://commit-m.minamijoyo.com/commits/search?keyword=japanese&page=1 Repository | sha1 | url | message ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- mozilla/pdf.js | 2da5727 | https://github.com/mozilla/pdf.js/commit/2da5727b6be34c3511c5147728c7885869c31c67 | Japanese locale vhf/free-programming-books | 1764a9a | https://github.com/vhf/free-programming-books/commit/1764a9a7c587e026e4e276726eaa204e0f9778c4 | Add Japanese book list vhf/free-programming-books | c4ed054 | https://github.com/vhf/free-programming-books/commit/c4ed054de9aa84a233dd99753ceac43f3990aa6c | add two japanese books adobe/brackets | d404fe1 | https://github.com/adobe/brackets/commit/d404fe10dba6f18857f498ddf8eaf5c19af91405 | Translate to Japanese. torvalds/linux | 8b43626 | https://github.com/torvalds/linux/commit/8b43626f0cdfb3154c57d52e732679c9d3484369 | HOWTO: sync Japanese HOWTO select2/select2 | edddf96 | https://github.com/select2/select2/commit/edddf961a1fbe3a77f120d000349916e006cc14a | Add Japanese translation discourse/discourse | 3f049f4 | https://github.com/discourse/discourse/commit/3f049f4853c6162601bccb2c91244f3762bea6ca | Provides Japanese locales discourse/discourse | e383921 | https://github.com/discourse/discourse/commit/e383921b349719ef46164554e2de3b897772a527 | Updated Japanese locales tiimgreen/github-cheat-sheet | 92141db | https://github.com/tiimgreen/github-cheat-sheet/commit/92141dbd831d58d8f1f3c9a04052858ef920ddf1 | Update Japanese translation tiimgreen/github-cheat-sheet | 3a95b5e | https://github.com/tiimgreen/github-cheat-sheet/commit/3a95b5ea3cb382ddb3d0f8ac836dcf4ad3af9f76 | Add Japanese translation h5bp/Front-end-Developer-Interview-Questions | 3b2098f | https://github.com/h5bp/Front-end-Developer-Interview-Questions/commit/3b2098ff5bb5b3c631efacf190065e9782831dc3 | Correct Japanese translateion. h5bp/Front-end-Developer-Interview-Questions | b79c222 | https://github.com/h5bp/Front-end-Developer-Interview-Questions/commit/b79c222d4566b65b4b3d999382a3078b0759644e | add Japanese translation airbnb/javascript | e484fa5 | https://github.com/airbnb/javascript/commit/e484fa58b13fffca55aae057eea406300bb05fc9 | translate into Japanese mozilla/pdf.js | bf2ebd3 | https://github.com/mozilla/pdf.js/commit/bf2ebd37140643a9ae37d2c47e07c53e454f860e | Updated Japanese locale (#3228) # 出力が多いので省略
検索ワードにヒットするコミットメッセージがたくさんあるときはページ処理されるので、1ページ目以外を見たいときは gommit-m 検索ワード ページ
のようにするといい感じ。
$ gommit-m japanese 2 Search Result : 103 results : 2/4 pages url: http://commit-m.minamijoyo.com/commits/search?keyword=japanese&page=2 Repository | sha1 | url | message --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- tiimgreen/github-cheat-sheet | d6e4a83 | https://github.com/tiimgreen/github-cheat-sheet/commit/d6e4a8311cd435e3df3f3e883e6f79b1670c2eff | Add link to Japanese translation laravel/laravel | cbff59b | https://github.com/laravel/laravel/commit/cbff59b59b922fce13abb2276b35f9eaf271b5f7 | Add Japanese language resource files. laravel/laravel | 2d2a6bf | https://github.com/laravel/laravel/commit/2d2a6bffa50c8057a42ea66ee183b4bbb06946cd | Add Japanese language resource files. django/django | f83e439 | https://github.com/django/django/commit/f83e439efac6a390d36e4da467db142eeb1003cc | fixed #2876: updated japanese translation django/django | 98d6eac | https://github.com/django/django/commit/98d6eac81c91c5852b4a84e412bcabc14f5b25c2 | fixed #1909: updated japanese translation mozilla/pdf.js | 0df411a | https://github.com/mozilla/pdf.js/commit/0df411a3da2e373ad76f960fd706736ef478e7ae | Fixes non-Japanese characters spacing vhf/free-programming-books | 8bf883b | https://github.com/vhf/free-programming-books/commit/8bf883b60b10165425989156ba44111a59df2fdd | Add cpprefjp, C++ Reference Site in Japanese vhf/free-programming-books | a2d71fd | https://github.com/vhf/free-programming-books/commit/a2d71fd9cc390622d88a4e99fdde91b765179549 | Fix some Japanese books for C++ vhf/free-programming-books | 5279934 | https://github.com/vhf/free-programming-books/commit/5279934859e976ad04ca633a3877aa2c340203ea | Add Machine Learning docs in Japanese. vhf/free-programming-books | 2671fe4 | https://github.com/vhf/free-programming-books/commit/2671fe4b9cc5fba20b8f71f860711e3d1caec849 | Add Spock Framework(Groovy) documents in Japanese. vhf/free-programming-books | 9012efc | https://github.com/vhf/free-programming-books/commit/9012efc964868ec344c86ef5575c15fe6bd9ff17 | Add Groovy/Gradle/Grails documents in Japanese. vhf/free-programming-books | 2809bc8 | https://github.com/vhf/free-programming-books/commit/2809bc88e365e65924fc1e8c12e22f8c5df14a10 | add into PHP section on Japanese Homebrew/homebrew | 05eceb8 | https://github.com/Homebrew/homebrew/commit/05eceb8eef84473ab7a4cd607721228160702cc9 | tmux: Correct japanese sonant mark display adobe/brackets | 275bdfe | https://github.com/adobe/brackets/commit/275bdfe32bc27010212d4049c9e08d123c8d1776 | Manually fix Japanese string and add URLs # 出力が多いので省略
ちょっとした工夫 - 整形
gommit-m はとても便利なのだけど、少し気になるところもあった。 たとえば↓のようなこととか。
- 表の横幅が大きいのでかなりフォントを小さくしないと折り返されてしまって見にくい
- URL はあまり必要な情報ではない
そこで gommit-m 検索ワード | awk -F'|' '{print $1 $2 $4}'
みたいなワンライナーで出力を整形したらかなりスッキリしていい感じになった。
$ gommit-m japanese | awk -F'|' '{print $1 $2 $4}' Search Result : 103 results : 1/4 pages url: http://commit-m.minamijoyo.com/commits/search?keyword=japanese&page=1 Repository sha1 message --------------------------------------------------------------------------------------------- mozilla/pdf.js 2da5727 Japanese locale vhf/free-programming-books 1764a9a Add Japanese book list vhf/free-programming-books c4ed054 add two japanese books adobe/brackets d404fe1 Translate to Japanese. torvalds/linux 8b43626 HOWTO: sync Japanese HOWTO select2/select2 edddf96 Add Japanese translation discourse/discourse 3f049f4 Provides Japanese locales discourse/discourse e383921 Updated Japanese locales tiimgreen/github-cheat-sheet 92141db Update Japanese translation tiimgreen/github-cheat-sheet 3a95b5e Add Japanese translation h5bp/Front-end-Developer-Interview-Questions 3b2098f Correct Japanese translateion. h5bp/Front-end-Developer-Interview-Questions b79c222 add Japanese translation airbnb/javascript e484fa5 translate into Japanese mozilla/pdf.js bf2ebd3 Updated Japanese locale (#3228)
ちょっとした工夫 - peco と連携
gommit-m の出力を対話的にフィルタリングしたくなったので gommit-m 検索ワード | awk -F'|' '{print $1 $2 $4}' | peco
みたいな感じで peco と連携させてみた。
出力が対話的にフィルタリングされるので検索ワードがどんな他のワードと組み合わせて使われているのかなどが視覚的に分かっていい感じ。
ちょっとした工夫 - GitHub のコミットページを見にいく
前のほうで URL はそれほど必要な情報ではないと書いたけど、ときどき「このコミットメッセージは実際のコミットはどうなってるんだろう」と見たくなることがあった。
ただ、URL はリポジトリ名と SHA1 ハッシュから求められるので URL 自体は出力に含めなくても大丈夫なようだった。
あと、常に実際のコミットを見たくなるわけでもないので以下のようなスクリプトを書いて、peco で行を選択したときに Github のコミットページをブラウザで開くようにして、peco を Esc
や C-c
でキャンセルしたときは何もしないようにしてみた *1
↓のスクリプトを gm とか適当な名前で保存して使うときは gm japanese
みたいな感じで使っている。
#!/bin/sh if [ $# -eq 0 ]; then echo 'usage: gm keyword [page]' exit 1 fi KEYWORD=$1 PAGE=${2:-1} RESULT=$(gommit-m $KEYWORD $PAGE | awk -F'|' '{print $1 $2 $4}' | peco --initial-index 5) if [ "$RESULT" = "" ]; then exit 0 fi echo $(echo $RESULT) REPO=$(echo $RESULT | awk '{print $1}') SHA1=$(echo $RESULT | awk '{print $2}') URL="https://github.com/$REPO/commit/$SHA1" open $URL # Mac を使ってるので open コマンドだけど Windows とかなら start コマンドとかでいい感じになると思う。たぶん。
コミットメッセージを書くのがだいぶ捗るようになった。
*1:あと雑なチェックとか