lazygitの設定ファイルの置き場所を変更するには
lazygitとは
gitのTUIです。
過去はtigや様々なGUIなども使ってきましたが、最近はこのlazygitを使うことが多いです。
設定ファイルについて
lazygitの設定ファイルはドキュメントによるとデフォルトではOS毎に以下のように配置されます。
- Linux:
~/.config/jesseduffield/lazygit/config.yml
- MacOS:
~/Library/Application Support/jesseduffield/lazygit/config.yml
- Windows:
%APPDATA%\jesseduffield\lazygit\config.yml
これについてはいくつかIssueが挙げられており議論はされているようなので、今後変更になる可能性はあります。
The path we now use is a mix of the xdg directory guidelines mixed with the (old) GoLang way of storing projects.
https://github.com/jesseduffield/lazygit/issues/913#issuecomment-669023281
設定ファイルの場所の変更方法
オプションを使う
コマンドのヘルプによると -ucd (--use-config-dir)
というオプションで設定ファイルを置くディレクトリを指定可能です。
$ lazygit --help
lazygit
Flags:
-h --help Displays help with available flag, subcommand, and positional value parameters.
-p --path Path of git repo. (equivalent to --work-tree=<path> --git-dir=<path>/.git/)
-f --filter Path to filter on in `git log -- <path>`. When in filter mode, the commits, reflog, and stash are filtered based on the given path, and some operations are restricted
-v --version Print the current version
-d --debug Run in debug mode with logging (see --logs flag below). Use the LOG_LEVEL env var to set the log level (debug/info/warn/error)
-l --logs Tail lazygit logs (intended to be used when `lazygit --debug` is called in a separate terminal tab)
-c --config Print the default config
-cd --print-config-dir Print the config directory
-ucd --use-config-dir override default config directory with provided directory
-w --work-tree equivalent of the --work-tree git argument
-g --git-dir equivalent of the --git-dir git argument
設定ファイルを ~/.config/lazygit/config.yml
にしたい場合は以下のようにオプションを指定して実行すればOKです。
毎回指定するのも面倒なのでエイリアスに登録してしまうのが簡単そうです。
$ lazygit -ucd ~/.config/lazygit
環境変数を使う
設定ファイルのディレクトリを決定する部分のコードを見ると CONFIG_DIR
という環境変数をみているようです。
-ucd
オプションはこの CONFIG_DIR
を上書きするようになっていますが、直接環境変数で CONFIG_DIR
を設定することでも同じことができました。
ただし CONFIG_DIR
という名前は一般的すぎる気がするので環境変数で制御するには少しためらわれます。
設定ファイルの場所を変えたいが -ucd
オプションは使いたくない、という状況でもなければ使うことはないでしょう。
(せめて LAZYGIT_CONFIG_DIR
のような名前になっていればと思いました)