@@ -2,6 +2,8 @@ package config
2
2
3
3
import (
4
4
"time"
5
+
6
+ "github.com/karimkhaleel/jsonschema"
5
7
)
6
8
7
9
type UserConfig struct {
@@ -25,26 +27,26 @@ type UserConfig struct {
25
27
// Lazygit sets this to true upon first runninng the program so that you don't see introductory popups every time you open the program.
26
28
DisableStartupPopups bool `yaml:"disableStartupPopups"`
27
29
// User-configured commands that can be invoked from within Lazygit
28
- CustomCommands []CustomCommand `yaml:"customCommands"`
30
+ CustomCommands []CustomCommand `yaml:"customCommands" jsonschema:"uniqueItems=true" `
29
31
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-pull-request-urls
30
32
Services map [string ]string `yaml:"services"`
31
33
// What to do when opening Lazygit outside of a git repo.
32
34
// - 'prompt': (default) ask whether to initialize a new repo or open in the most recent repo
33
35
// - 'create': initialize a new repo
34
36
// - 'skip': open most recent repo
35
37
// - 'quit': exit Lazygit
36
- NotARepository string `yaml:"notARepository"`
38
+ NotARepository string `yaml:"notARepository" jsonschema:"enum=prompt,enum=create,enum=skip,enum=quit" `
37
39
// If true, display a confirmation when subprocess terminates. This allows you to view the output of the subprocess before returning to Lazygit.
38
40
PromptToReturnFromSubprocess bool `yaml:"promptToReturnFromSubprocess"`
39
41
}
40
42
41
43
type RefresherConfig struct {
42
44
// File/submodule refresh interval in seconds.
43
45
// Auto-refresh can be disabled via option 'git.autoRefresh'.
44
- RefreshInterval int `yaml:"refreshInterval"`
46
+ RefreshInterval int `yaml:"refreshInterval" jsonschema:"minimum=0" `
45
47
// Re-fetch interval in seconds.
46
48
// Auto-fetch can be disabled via option 'git.autoFetch'.
47
- FetchInterval int `yaml:"fetchInterval"`
49
+ FetchInterval int `yaml:"fetchInterval" jsonschema:"minimum=0" `
48
50
}
49
51
50
52
type GuiConfig struct {
@@ -53,7 +55,7 @@ type GuiConfig struct {
53
55
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-branch-color
54
56
BranchColors map [string ]string `yaml:"branchColors"`
55
57
// The number of lines you scroll by when scrolling the main window
56
- ScrollHeight int `yaml:"scrollHeight"`
58
+ ScrollHeight int `yaml:"scrollHeight" jsonschema:"minimum=1" `
57
59
// If true, allow scrolling past the bottom of the content in the main window
58
60
ScrollPastBottom bool `yaml:"scrollPastBottom"`
59
61
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#scroll-off-margin
@@ -73,17 +75,17 @@ type GuiConfig struct {
73
75
SkipRewordInEditorWarning bool `yaml:"skipRewordInEditorWarning"`
74
76
// Fraction of the total screen width to use for the left side section. You may want to pick a small number (e.g. 0.2) if you're using a narrow screen, so that you can see more of the main section.
75
77
// Number from 0 to 1.0.
76
- SidePanelWidth float64 `yaml:"sidePanelWidth"`
78
+ SidePanelWidth float64 `yaml:"sidePanelWidth" jsonschema:"maximum=1,minimum=0" `
77
79
// If true, increase the height of the focused side window; creating an accordion effect.
78
80
ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"`
79
81
// Sometimes the main window is split in two (e.g. when the selected file has both staged and unstaged changes). This setting controls how the two sections are split.
80
82
// Options are:
81
83
// - 'horizontal': split the window horizontally
82
84
// - 'vertical': split the window vertically
83
85
// - 'flexible': (default) split the window horizontally if the window is wide enough, otherwise split vertically
84
- MainPanelSplitMode string `yaml:"mainPanelSplitMode"`
86
+ MainPanelSplitMode string `yaml:"mainPanelSplitMode" jsonschema:"enum=horizontal,enum=flexible,enum=vertical" `
85
87
// One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
86
- Language string `yaml:"language"`
88
+ Language string `yaml:"language" jsonschema:"enum=auto,enum=en,enum=zh-TW,enum=zh-CN,enum=pl,enum=nl,enum=ja,enum=ko,enum=ru" `
87
89
// Format used when displaying time e.g. commit time.
88
90
// Uses Go's time format syntax: https://pkg.go.dev/time#Time.Format
89
91
TimeFormat string `yaml:"timeFormat"`
@@ -113,21 +115,21 @@ type GuiConfig struct {
113
115
// Nerd fonts version to use.
114
116
// One of: '2' | '3' | empty string (default)
115
117
// If empty, do not show icons.
116
- NerdFontsVersion string `yaml:"nerdFontsVersion"`
118
+ NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum=" `
117
119
// If true, show commit hashes alongside branch names in the branches view.
118
120
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
119
121
// Height of the command log view
120
- CommandLogSize int `yaml:"commandLogSize"`
122
+ CommandLogSize int `yaml:"commandLogSize" jsonschema:"minimum=0" `
121
123
// Whether to split the main window when viewing file changes.
122
124
// One of: 'auto' | 'always'
123
125
// If 'auto', only split the main window when a file has both staged and unstaged changes
124
- SplitDiff string `yaml:"splitDiff"`
126
+ SplitDiff string `yaml:"splitDiff" jsonschema:"enum=auto,enum=always" `
125
127
// Default size for focused window. Window size can be changed from within Lazygit with '+' and '_' (but this won't change the default).
126
128
// One of: 'normal' (default) | 'half' | 'full'
127
- WindowSize string `yaml:"windowSize"`
129
+ WindowSize string `yaml:"windowSize" jsonschema:"enum=normal,enum=half,enum=full" `
128
130
// Window border style.
129
131
// One of 'rounded' (default) | 'single' | 'double' | 'hidden'
130
- Border string `yaml:"border"`
132
+ Border string `yaml:"border" jsonschema:"enum=single,enum=double,enum=rounded,enum=hidden" `
131
133
// If true, show a seriously epic explosion animation when nuking the working tree.
132
134
AnimateExplosion bool `yaml:"animateExplosion"`
133
135
// Whether to stack UI components on top of each other.
@@ -137,31 +139,31 @@ type GuiConfig struct {
137
139
138
140
type ThemeConfig struct {
139
141
// Border color of focused window
140
- ActiveBorderColor []string `yaml:"activeBorderColor"`
142
+ ActiveBorderColor []string `yaml:"activeBorderColor" jsonschema:"minItems=1,uniqueItems=true" `
141
143
// Border color of non-focused windows
142
- InactiveBorderColor []string `yaml:"inactiveBorderColor"`
144
+ InactiveBorderColor []string `yaml:"inactiveBorderColor" jsonschema:"minItems=1,uniqueItems=true" `
143
145
// Border color of focused window when searching in that window
144
- SearchingActiveBorderColor []string `yaml:"searchingActiveBorderColor"`
146
+ SearchingActiveBorderColor []string `yaml:"searchingActiveBorderColor" jsonschema:"minItems=1,uniqueItems=true" `
145
147
// Color of keybindings help text in the bottom line
146
- OptionsTextColor []string `yaml:"optionsTextColor"`
148
+ OptionsTextColor []string `yaml:"optionsTextColor" jsonschema:"minItems=1,uniqueItems=true" `
147
149
// Background color of selected line.
148
150
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
149
- SelectedLineBgColor []string `yaml:"selectedLineBgColor"`
151
+ SelectedLineBgColor []string `yaml:"selectedLineBgColor" jsonschema:"minItems=1,uniqueItems=true" `
150
152
// Background color of selected range
151
153
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
152
- SelectedRangeBgColor []string `yaml:"selectedRangeBgColor"`
154
+ SelectedRangeBgColor []string `yaml:"selectedRangeBgColor" jsonschema:"minItems=1,uniqueItems=true" `
153
155
// Foreground color of copied commit
154
- CherryPickedCommitFgColor []string `yaml:"cherryPickedCommitFgColor"`
156
+ CherryPickedCommitFgColor []string `yaml:"cherryPickedCommitFgColor" jsonschema:"minItems=1,uniqueItems=true" `
155
157
// Background color of copied commit
156
- CherryPickedCommitBgColor []string `yaml:"cherryPickedCommitBgColor"`
158
+ CherryPickedCommitBgColor []string `yaml:"cherryPickedCommitBgColor" jsonschema:"minItems=1,uniqueItems=true" `
157
159
// Foreground color of marked base commit (for rebase)
158
160
MarkedBaseCommitFgColor []string `yaml:"markedBaseCommitFgColor"`
159
161
// Background color of marked base commit (for rebase)
160
162
MarkedBaseCommitBgColor []string `yaml:"markedBaseCommitBgColor"`
161
163
// Color for file with unstaged changes
162
- UnstagedChangesColor []string `yaml:"unstagedChangesColor"`
164
+ UnstagedChangesColor []string `yaml:"unstagedChangesColor" jsonschema:"minItems=1,uniqueItems=true" `
163
165
// Default text color
164
- DefaultFgColor []string `yaml:"defaultFgColor"`
166
+ DefaultFgColor []string `yaml:"defaultFgColor" jsonschema:"minItems=1,uniqueItems=true" `
165
167
}
166
168
167
169
type CommitLengthConfig struct {
@@ -177,7 +179,7 @@ type GitConfig struct {
177
179
// Config relating to merging
178
180
Merging MergingConfig `yaml:"merging"`
179
181
// list of branches that are considered 'main' branches, used when displaying commits
180
- MainBranches []string `yaml:"mainBranches"`
182
+ MainBranches []string `yaml:"mainBranches" jsonschema:"uniqueItems=true" `
181
183
// Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'
182
184
SkipHookPrefix string `yaml:"skipHookPrefix"`
183
185
// If true, periodically fetch from remote
@@ -203,14 +205,24 @@ type GitConfig struct {
203
205
Log LogConfig `yaml:"log"`
204
206
}
205
207
208
+ type PagerType string
209
+
210
+ func (PagerType ) JSONSchemaExtend (schema * jsonschema.Schema ) {
211
+ schema .Examples = []any {
212
+ "delta --dark --paging=never" ,
213
+ "diff-so-fancy" ,
214
+ "ydiff -p cat -s --wrap --width={{columnWidth}}" ,
215
+ }
216
+ }
217
+
206
218
type PagingConfig struct {
207
219
// Value of the --color arg in the git diff command. Some pagers want this to be set to 'always' and some want it set to 'never'
208
- ColorArg string `yaml:"colorArg"`
220
+ ColorArg string `yaml:"colorArg" jsonschema:"enum=always,enum=never" `
209
221
// e.g.
210
222
// diff-so-fancy
211
223
// delta --dark --paging=never
212
224
// ydiff -p cat -s --wrap --width={{columnWidth}}
213
- Pager string `yaml:"pager"`
225
+ Pager PagerType `yaml:"pager" jsonschema:"minLength=1 "`
214
226
// If true, Lazygit will use whatever pager is specified in `$GIT_PAGER`, `$PAGER`, or your *git config*. If the pager ends with something like ` | less` we will strip that part out, because less doesn't play nice with our rendering approach. If the custom pager uses less under the hood, that will also break rendering (hence the `--paging=never` flag for the `delta` pager).
215
227
UseConfig bool `yaml:"useConfig"`
216
228
// e.g. 'difft --color=always'
@@ -227,33 +239,33 @@ type MergingConfig struct {
227
239
// Only applicable to unix users.
228
240
ManualCommit bool `yaml:"manualCommit"`
229
241
// Extra args passed to `git merge`, e.g. --no-ff
230
- Args string `yaml:"args"`
242
+ Args string `yaml:"args" jsonschema:"example=--no-ff" `
231
243
}
232
244
233
245
type LogConfig struct {
234
- // One of: 'date-order' | 'author-date-order' | 'topo-order'
246
+ // One of: 'date-order' | 'author-date-order' | 'topo-order | default '
235
247
// 'topo-order' makes it easier to read the git log graph, but commits may not
236
248
// appear chronologically. See https://git-scm.com/docs/
237
- Order string `yaml:"order"`
249
+ Order string `yaml:"order" jsonschema:"enum=date-order,enum=author-date-order,enum=topo-order,enum=default" `
238
250
// This determines whether the git graph is rendered in the commits panel
239
- // One of 'always' | 'never' 'when-maximised'
240
- ShowGraph string `yaml:"showGraph"`
251
+ // One of 'always' | 'never' | 'when-maximised'
252
+ ShowGraph string `yaml:"showGraph" jsonschema:"enum=always,enum=never,enum=when-maximised" `
241
253
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
242
254
ShowWholeGraph bool `yaml:"showWholeGraph"`
243
255
}
244
256
245
257
type CommitPrefixConfig struct {
246
258
// pattern to match on. E.g. for 'feature/AB-123' to match on the AB-123 use "^\\w+\\/(\\w+-\\w+).*"
247
- Pattern string `yaml:"pattern"`
259
+ Pattern string `yaml:"pattern" jsonschema:"example=^\\w+\\/(\\w+-\\w+).*,minLength=1" `
248
260
// Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] "
249
- Replace string `yaml:"replace"`
261
+ Replace string `yaml:"replace" jsonschema:"example=[$1] ,minLength=1" `
250
262
}
251
263
252
264
type UpdateConfig struct {
253
265
// One of: 'prompt' (default) | 'background' | 'never'
254
- Method string `yaml:"method"`
266
+ Method string `yaml:"method" jsonschema:"enum=prompt,enum=background,enum=never" `
255
267
// Period in days between update checks
256
- Days int64 `yaml:"days"`
268
+ Days int64 `yaml:"days" jsonschema:"minimum=0" `
257
269
}
258
270
259
271
type KeybindingConfig struct {
@@ -459,7 +471,7 @@ type OSConfig struct {
459
471
460
472
// A built-in preset that sets all of the above settings. Supported presets
461
473
// are defined in the getPreset function in editor_presets.go.
462
- EditPreset string `yaml:"editPreset,omitempty"`
474
+ EditPreset string `yaml:"editPreset,omitempty" jsonschema:"example=vim,example=nvim,example=emacs,example=nano,example=vscode,example=sublime,example=kakoune,example=helix,example=xcode" `
463
475
464
476
// Command for opening a file, as if the file is double-clicked. Should
465
477
// contain "{{filename}}", but doesn't support "{{line}}".
@@ -504,15 +516,15 @@ type CustomCommand struct {
504
516
// The key to trigger the command. Use a single letter or one of the values from https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md
505
517
Key string `yaml:"key"`
506
518
// The context in which to listen for the key
507
- Context string `yaml:"context"`
519
+ Context string `yaml:"context" jsonschema:"enum=status,enum=files,enum=worktrees,enum=localBranches,enum=remotes,enum=remoteBranches,enum=tags,enum=commits,enum=reflogCommits,enum=subCommits,enum=commitFiles,enum=stash,enum=global" `
508
520
// The command to run (using Go template syntax for placeholder values)
509
- Command string `yaml:"command"`
521
+ Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD" `
510
522
// If true, run the command in a subprocess (e.g. if the command requires user input)
511
523
Subprocess bool `yaml:"subprocess"`
512
524
// A list of prompts that will request user input before running the final command
513
525
Prompts []CustomCommandPrompt `yaml:"prompts"`
514
526
// Text to display while waiting for command to finish
515
- LoadingText string `yaml:"loadingText"`
527
+ LoadingText string `yaml:"loadingText" jsonschema:"example=Loading..." `
516
528
// Label for the custom command when displayed in the keybindings menu
517
529
Description string `yaml:"description"`
518
530
// If true, stream the command's output to the Command Log panel
@@ -540,31 +552,31 @@ type CustomCommandPrompt struct {
540
552
541
553
// The message of the confirmation prompt.
542
554
// Only for confirm prompts.
543
- Body string `yaml:"body"`
555
+ Body string `yaml:"body" jsonschema:"example=Are you sure you want to push to the remote?" `
544
556
545
557
// Menu options.
546
558
// Only for menu prompts.
547
559
Options []CustomCommandMenuOption
548
560
549
561
// The command to run to generate menu options
550
562
// Only for menuFromCommand prompts.
551
- Command string `yaml:"command"`
563
+ Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD" `
552
564
// The regexp to run specifying groups which are going to be kept from the command's output.
553
565
// Only for menuFromCommand prompts.
554
- Filter string `yaml:"filter"`
566
+ Filter string `yaml:"filter" jsonschema:"example=.*{{.SelectedRemote.Name }}/(?P<branch>.*)" `
555
567
// How to format matched groups from the filter to construct a menu item's value.
556
568
// Only for menuFromCommand prompts.
557
- ValueFormat string `yaml:"valueFormat"`
569
+ ValueFormat string `yaml:"valueFormat" jsonschema:"example={{ .branch }}" `
558
570
// Like valueFormat but for the labels. If `labelFormat` is not specified, `valueFormat` is shown instead.
559
571
// Only for menuFromCommand prompts.
560
- LabelFormat string `yaml:"labelFormat"`
572
+ LabelFormat string `yaml:"labelFormat" jsonschema:"example={{ .branch | green }}" `
561
573
}
562
574
563
575
type CustomCommandSuggestions struct {
564
576
// Uses built-in logic to obtain the suggestions. One of 'authors' | 'branches' | 'files' | 'refs' | 'remotes' | 'remoteBranches' | 'tags'
565
- Preset string `yaml:"preset"`
577
+ Preset string `yaml:"preset" jsonschema:"enum=authors,enum=branches,enum=files,enum=refs,enum=remotes,enum=remoteBranches,enum=tags" `
566
578
// Command to run such that each line in the output becomes a suggestion. Mutually exclusive with 'preset' field.
567
- Command string `yaml:"command"`
579
+ Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD" `
568
580
}
569
581
570
582
type CustomCommandMenuOption struct {
@@ -573,7 +585,7 @@ type CustomCommandMenuOption struct {
573
585
// The second part of the label
574
586
Description string `yaml:"description"`
575
587
// The value that will be used in the command
576
- Value string `yaml:"value"`
588
+ Value string `yaml:"value" jsonschema:"example=feature,minLength=1" `
577
589
}
578
590
579
591
func GetDefaultConfig () * UserConfig {
0 commit comments