[[Lazygit]]で[[カスタムコマンド (Lazygit)|カスタムコマンド]]を定義する方法。[[Lazygit]]の設定ファイルに以下のように追加する。
```yaml
customCommands:
- key: 'a'
context: 'files'
command: "git {{if .SelectedFile.HasUnstagedChanges}} add {{else}} reset {{end}} {{.SelectedFile.Name | quote}}"
description: 'Toggle file staged'
```
## コミットの選択範囲全体に対して適応
diff系のコマンドで指定した範囲の差分を指定したいときは `SelectedCommitRange` を使う。
```yaml
command: "hunk diff {{.SelectedCommitRange.From}}^1..{{.SelectedCommitRange.To}}"
```
## ショートカットキーを設定したくない場合
`?`で[[カスタムコマンド (Lazygit)|カスタムコマンド]]を実行できるように登録したいが、ショートカットキーで発動したくないケースがある。しかし、`key`は必須プロパティなので省略はできない。この場合は`key`に空文字を指定する。
```yaml
customCommands:
- key: ''
context: 'files'
command: "git {{if .SelectedFile.HasUnstagedChanges}} add {{else}} reset {{end}} {{.SelectedFile.Name | quote}}"
description: 'Toggle file staged'
```
> [!note]
> [[Lazygit]] 0.62 で普通に指定できるようになったかも?