feature image

2023年9月14日 | ブログ記事

Emoji Prefix with your `core.editor`

この記事は、夏のブログリレー25日目の記事です。


こんにちは。20Bの@Rasです。

Gitでコミットを生成するときに先頭に絵文字 (以下Emoji) を付ける「Emoji Prefix」を採用しています。

先頭につけるEmojiのルールは好みやチームの方針によって異なりますが、新規機能の実装には「✨」、バグの修正には「🐛」などを付けることが多いです。

Emoji PrefixをGitHubで見たときの様子

Emoji Prefixを用いることの利点は以下のようなものです。

今回は、Emoji Prefixの詳細な説明や使い方は他のサイトに任せます。
個人的にはgitmojiがお気に入りです。

gitmoji
An emoji guide for your commit messages.

使うハードルが高い問題

Emoji Prefixを軽く紹介しましたが、現時点では以下の点が課題になり得ます。

Emoji Prefix用ツール参戦

これらの問題を解決するために、先ほど紹介したgitmojiのCLI版である carloscuesta/gitmoji-clicommitizen/cz-cli (正確にはcommitizenの拡張であるngryman/cz-emoji)といったツールがあります。

GitHub - carloscuesta/gitmoji-cli: A gitmoji interactive command line tool for using emojis on commits. 💻
A gitmoji interactive command line tool for using emojis on commits. 💻 - GitHub - carloscuesta/gitmoji-cli: A gitmoji interactive command line tool for using emojis on commits. 💻
GitHub - commitizen/cz-cli: The commitizen command line utility. #BlackLivesMatter
The commitizen command line utility. #BlackLivesMatter - GitHub - commitizen/cz-cli: The commitizen command line utility. #BlackLivesMatter
GitHub - ngryman/cz-emoji: Commitizen adapter formatting commit messages using emojis.
Commitizen adapter formatting commit messages using emojis. - GitHub - ngryman/cz-emoji: Commitizen adapter formatting commit messages using emojis.

これらのツールでは自分が使いたいEmojiのリストを登録して、以下のように対話形式でコミットを生成することができます。

  1. コミットメッセージの先頭に来るEmojiを決める
  2. コミットメッセージを打つ
  3. コミットを生成する

限られたEmojiのリストの中から探すことができ、検索も利くため先ほどの課題を解決することができます。

Emoji Prefixツールの課題

gitmoji-cliやcommitizenを使うことで、対話形式でEmoji Prefixを付けたコミットを生成することができる様になりました。

しかし、既にGitに慣れ親しんだ方からすれば、自分がこれまで使っていたコミット用エディタ(core.editor)からこれらのツールに置き換える必要が出てきてしまいました。

@Rasはコミット用エディタにVimを使っています。
一度はcommitizenやgitmoji-cliを試しましたが、Vimでこれまで高速にできていたコミットが対話形式になったことで煩わしさを感じるようになり、再度Vimに戻ってしまいました。

$ git config --global core.editor
vim

そこで... Emoji Prefix with your core.editor

要はこれまでのコミット用エディタでコミットメッセージを打つ際に文字を打つかのようにEmojiを打つことができれば最高なわけです。
タイトル詐欺みたいですが、ここではVimでの方法のみ紹介します(@RasがコミットにVimしか使わないため)。

Vimにはabbreviation(短縮入力)の機能があります。これを使うことで快適なEmoji Prefix環境を簡単に用意することができます。

Vimの設定ファイルである.vimrcに以下を記述します。

" git commit prefix
augroup gitabbr
  autocmd!
  " ✨ fe: Introduce new features.
  autocmd FileType gitcommit iabbrev fe :sparkles:
  " 🐛 bu: Fix a bug.
  autocmd FileType gitcommit iabbrev bu :bug:
  " 🩹 ad: Simple fix for a non-critical issue.
  autocmd FileType gitcommit iabbrev ad :adhesive_bandage:
  " ♻️ re: Refactor code.
  autocmd FileType gitcommit iabbrev re :recycle:
  " 💥 bo: Introduce breaking changes.
  autocmd FileType gitcommit iabbrev bo :boom:
  " 🔥 rm: Remove code or files.
  autocmd FileType gitcommit iabbrev rm :fire:
  " 🎨 fo: Improve structure / format of the code.
  autocmd FileType gitcommit iabbrev fo :art:
  " 💄 ui: Add or update the UI and style files.
  autocmd FileType gitcommit iabbrev ui :lipstick:
  " 🔧 co: Add or update configuration files.
  autocmd FileType gitcommit iabbrev co :wrench:
  " 📝 do: Add or update documentation.
  autocmd FileType gitcommit iabbrev do :memo:
  " ⬆️ up: Upgrade dependencies.
  autocmd FileType gitcommit iabbrev up :arrow_up:
augroup END
autocmd FileType gitcommit iabbrev fe :sparkles:

は、ファイルタイプがgitcommitのとき且つインサートモードのときにfeと打つと:sparkles:に変換されることを意味します。

これを設定すると、あまりにもスムーズにEmoji付きのコミットを生成することができます🎉

0:00
/
ス、スムーズすぎる...

おまけ

commit.templateを設定しておくとチートができて便利です。
上の動画でも登場しています。

$ git config --global commit.template
~/.gittemplate.txt

$ cat ~/.gittemplate.txt


# ✨ fe: Introduce new features.
# 🐛 bu: Fix a bug.
# 🩹 ad: Simple fix for a non-critical issue.
# ♻️  re: Refactor code.
# 💥 bo: Introduce breaking changes.
# 🎨 fo: Improve structure / format of the code.
# 🔥 rm: Remove code or files.
# 💄 ui: Add or update the UI and style files.
# 🔧 co: Add or update configuration files.
# 📝 do: Add or update documentation.
# ⬆️  up: Upgrade dependencies.

参考


明日の担当者は@abap34です!お楽しみに!

Ras icon
この記事を書いた人
Ras

20B。アライグマです。

この記事をシェア

このエントリーをはてなブックマークに追加
共有

関連する記事

2021年8月12日
CPCTFを支えたWebshell
mazrean icon mazrean
2022年9月26日
競プロしかシラン人間が web アプリ QK Judge を作った話
tqk icon tqk
2022年9月16日
5日でゲームを作った #tararira
Komichi icon Komichi
2023年9月27日
夏のブログリレーは終わらない【駄文】
Komichi icon Komichi
2023年9月13日
ブログリレーを支えるリマインダー
H1rono_K icon H1rono_K
2023年8月21日
名取さなになりたくてOBSと連携する配信画面を作った
d_etteiu8383 icon d_etteiu8383
記事一覧 タグ一覧 Google アナリティクスについて 特定商取引法に基づく表記