ターミナルがダサいとモテない。git-deltaでgit diff/lazygitをside-by-sideでおしゃれ表示

ターミナルがダサいとモテない。git-deltaでgit diff/lazygitをside-by-sideでおしゃれ表示

Photo by Yancy Min on Unsplash

git-delta使ってますか?

うちの社内でneovimユーザーを増やそうとしているんですが、git clientがやっぱり障壁になるんだなと・・・

そこでlazygitを伝えたんですが、ついでなのでMediumに😆

VS Codeで触った方がいいだろうし、GUIの方がいいのもそうだと思います。
Command-Lineだと確かにめんどくさい。
Linuxのインフラ系エンジニアしかgit command触らないんじゃないかと勝手に思ったりしてます🐧

Install delta

GitHub - dandavison/delta: A syntax-highlighting pager for git, diff, grep, and blame output

A syntax-highlighting pager for git, diff, grep, and blame output - dandavison/delta

github.com

deltaはけっこう有名なツールなので検索するといっぱい出てくると思います。

CLIでもside-by-sideで表示してくれ、見やすくて自分はこれがないと辛いくらいです。

side-by-sideってなんだってなると思いますが上のgithubのLinkから見れるので、見ていただければすぐわかって頂けると思います。

macOSであればbrewでも入ります。

Plain text
brew install git-delta

自分はcargoでInstallしてます。
Rustのセットアップが必要ですが、cargoでのInstallはこちら

Plain text
cargo install git-delta

Install lazygit

lazygitはTerminal用のgit clientです。

GitHub - jesseduffield/lazygit: simple terminal UI for git commands

simple terminal UI for git commands. Contribute to jesseduffield/lazygit development by creating an account on GitHub.

github.com

NeoVimAstroNvimはlazygitに対応していてtoggle terminalでlazygitを呼び出すことができます。

実際のInstallはこちらにあります。

GitHub - jesseduffield/lazygit: simple terminal UI for git commands

simple terminal UI for git commands. Contribute to jesseduffield/lazygit development by creating an account on GitHub.

github.com

macOSならbrewでも良いですし、go installでも入ります。

Plain text
brew install jesseduffield/lazygit/lazygit
brew install lazygit

自分はgo installで入れてます。

Plain text
go install github.com/jesseduffield/lazygit@latest

実際のAstroNvimからの呼び出しはここに

⌨️ Mappings

The documentation website for AstroNvim.

docs.astronvim.com

他にも設定次第ではありますが、 Leader + gg でも呼べると思います。

lazygit config.yml path

またlazygitのconfig default pathがmacOSだと痒い場所なので変えます😁

configのdefault pathはここを見るとわかります。

lazygit/docs/Config.md at master · jesseduffield/lazygit

simple terminal UI for git commands. Contribute to jesseduffield/lazygit development by creating an account on GitHub.

github.com

~/Library/Application\ Support/lazygit/config.yml

自分はbashなので以下でLG_CONFIG_FILEを設定してます。

ついでにlazygitって長いのでlgってaliasを貼るんですが、lazygitのargsを活かしたいのでfunctionで呼びます😂

Plain text
if command -v lazygit &> /dev/null; then
  declare -x LG_CONFIG_FILE=~/.config/lazygit/config.yml
  export LG_CONFIG_FILE

  function lg(){
    lazygit "$@"
  }
fi

これで今いるdirectoryがgitのrepositoryならlazygitが起動します。

lazygit config.yml

自分の設定は以下です。

しっかりgit-deltaもdraculaです🧛
siginingは必要ない人は削ってください🔐

Plain text
git:
  autocommit: false
  signing:
    key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    signOff: true
  paging:
    colorArg: always
    pager: delta --paging=never --true-color=auto --dark --side-by-side --line-numbers --syntax-theme=Dracula --width=variable --navigate
    #useConfig: true
#
gui:
  # DRACULA
  theme:
    activeBorderColor:
      - "#FF79C6"
      - bold
    inactiveBorderColor:
      - "#BD93F9"

    searchingActiveBorderColor:
      - "#8BE9FD"
      - bold

    optionsTextColor:
      - "#6272A4"

    selectedLineBgColor:
      - "#6272A4"

    inactiveViewSelectedLineBgColor:
      - bold

    cherryPickedCommitFgColor:
      - "#6272A4"

    cherryPickedCommitBgColor:
      - "#8BE9FD"

    markedBaseCommitFgColor:
      - "#8BE9FD"

    markedBaseCommitBgColor:
      - "#F1FA8C"

    unstagedChangesColor:
      - "#FF5555"

    defaultFgColor:
      - "#F8F8F2"

これでAstroNvimからlazygitを呼び出してlazygitの差分表示をside-by-sideにおしゃれ表示できます。

個人的にはこれがないと差分見たくないくらいです😂

Appendix: git + git-delta

git command自体にもgit-deltaを適用できます。
自分はこんな設定にしています。

Plain text
[pager]
  diff = delta
  log = delta
  reflog = delta
  show = delta

[delta]
  width = variable
  true-color = always
  dark = true
  light = false
  features = "side-by-side line-numbers"
  syntax-theme = Dracula
  navigate = true
  line-numbers = true
  side-by-side = true
  wrap = true

git [log|reflog]だけ-pを付ける必要がありますがside-by-side表示されます🚙

Plain text
git log -p
git reflog -p

ターミナル環境について他の記事も書いているので、よろしければこちらもご覧ください!
『ターミナルがダサいとモテない』シリーズ一覧

転載:ターミナルがダサいとモテない。git-deltaでgit diff/lazygitをside-by-sideでおしゃれ表示

この記事は Medium(@yusuke_h) からの転載です。