Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-master/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ keybinding:
startSearch: /
optionMenu: <disabled>
optionMenu-alt1: '?'
gitConfig: ;
select: <space>
goInto: <enter>
confirm: <enter>
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | Increase diff context size | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | Decrease diff context size | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | Execute shell command | Bring up a prompt where you can enter a shell command to execute. |
| `` <c-p> `` | View custom patch options | |
| `` m `` | View merge/rebase options | View options to abort/continue/skip the current merge/rebase. |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味
| `` ( `` | リネーム検出の類似度しきい値を下げる | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | 差分コンテキストサイズを増やす | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | 差分コンテキストサイズを減らす | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | シェルコマンドを実行 | 実行するシェルコマンドを入力するプロンプトを表示します。 |
| `` <c-p> `` | カスタムパッチオプションを表示 | |
| `` m `` | マージ/リベースオプションを表示 | 現在のマージ/リベースを中止/継続/スキップするオプションを表示します。 |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | Diff 보기의 변경 사항 주위에 표시되는 컨텍스트의 크기를 늘리기 | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | Diff 보기의 변경 사항 주위에 표시되는 컨텍스트 크기 줄이기 | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | Execute shell command | Bring up a prompt where you can enter a shell command to execute. |
| `` <c-p> `` | 커스텀 Patch 옵션 보기 | |
| `` m `` | View merge/rebase options | View options to abort/continue/skip the current merge/rebase. |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | Increase diff context size | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | Decrease diff context size | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | Execute shell command | Bring up a prompt where you can enter a shell command to execute. |
| `` <c-p> `` | Bekijk aangepaste patch opties | |
| `` m `` | Bekijk merge/rebase opties | View options to abort/continue/skip the current merge/rebase. |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _Legenda: `<c-b>` oznacza ctrl+b, `<a-b>` oznacza alt+b, `B` oznacza shift+b_
| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | Zwiększ rozmiar kontekstu w widoku różnic | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | Zmniejsz rozmiar kontekstu w widoku różnic | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | Execute shell command | Bring up a prompt where you can enter a shell command to execute. |
| `` <c-p> `` | Wyświetl opcje niestandardowej łatki | |
| `` m `` | Pokaż opcje scalania/rebase | Pokaż opcje do przerwania/kontynuowania/pominięcia bieżącego scalania/rebase. |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | Increase diff context size | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | Decrease diff context size | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | Executar comando da shell | Traga um prompt onde você pode digitar um comando shell para executar. |
| `` <c-p> `` | Ver opções de patch personalizadas | |
| `` m `` | Ver opções de mesclar/rebase | Ver opções para abortar/continuar/pular o merge/rebase atual. |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _Связки клавиш_
| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | Увеличить размер контекста, отображаемого вокруг изменений в просмотрщике сравнении | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | Уменьшите размер контекста, отображаемого вокруг изменений в просмотрщике сравнении | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | Execute shell command | Bring up a prompt where you can enter a shell command to execute. |
| `` <c-p> `` | Просмотреть пользовательские параметры патча | |
| `` m `` | Просмотреть параметры слияния/перебазирования | View options to abort/continue/skip the current merge/rebase. |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _图例:`<c-b>` 意味着ctrl+b, `<a-b>意味着Alt+b, `B` 意味着shift+b_
| `` ( `` | 降低重命名相似度阈值 | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | 扩大差异视图中显示的上下文范围 | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | 缩小差异视图中显示的上下文范围 | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | 执行 Shell 命令 | 调出可输入shell命令执行的提示符。 |
| `` <c-p> `` | 查看自定义补丁选项 | |
| `` m `` | 查看合并/变基选项 | 查看当前合并或变基的中止、继续、跳过选项 |
Expand Down
1 change: 1 addition & 0 deletions docs-master/keybindings/Keybindings_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.<br><br>The default can be changed in the config file with the key 'git.renameSimilarityThreshold'. |
| `` } `` | 增加差異檢視中顯示變更周圍上下文的大小 | Increase the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` { `` | 減小差異檢視中顯示變更周圍上下文的大小 | Decrease the amount of the context shown around changes in the diff view.<br><br>The default can be changed in the config file with the key 'git.diffContextSize'. |
| `` ; `` | Git config | |
| `` : `` | Execute shell command | Bring up a prompt where you can enter a shell command to execute. |
| `` <c-p> `` | 檢視自訂補丁選項 | |
| `` m `` | 查看合併/變基選項 | View options to abort/continue/skip the current merge/rebase. |
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewGitCommandAux(
// and allows for better namespacing when compared to having every method living
// on the one struct.
// common ones are: cmn, osCommand, dotGitDir, configCommands
configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo)
configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo, cmd)

gitCommon := git_commands.NewGitCommon(cmn, version, cmd, osCommand, repoPaths, repo, configCommands, pagerConfig)

Expand Down
72 changes: 72 additions & 0 deletions pkg/commands/git_commands/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package git_commands

import (
"strings"

gogit "github.com/jesseduffield/go-git/v5"
"github.com/jesseduffield/go-git/v5/config"
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common"
)

Expand All @@ -12,17 +15,20 @@ type ConfigCommands struct {

gitConfig git_config.IGitConfig
repo *gogit.Repository
cmd oscommands.ICmdObjBuilder
}

func NewConfigCommands(
common *common.Common,
gitConfig git_config.IGitConfig,
repo *gogit.Repository,
cmd oscommands.ICmdObjBuilder,
) *ConfigCommands {
return &ConfigCommands{
Common: common,
gitConfig: gitConfig,
repo: repo,
cmd: cmd,
}
}

Expand Down Expand Up @@ -101,6 +107,72 @@ func (self *ConfigCommands) GetMergeFF() string {
return self.gitConfig.Get("merge.ff")
}

func (self *ConfigCommands) ListLocalConfig() map[string]string {
return self.listConfig("--local")
}

func (self *ConfigCommands) ListGlobalConfig() map[string]string {
return self.listConfig("--global")
}

func (self *ConfigCommands) ListSystemConfig() map[string]string {
return self.listConfig("--system")
}

func (self *ConfigCommands) GetLocalConfigValue(key string) string {
return self.gitConfig.GetGeneral("--local --get " + key)
}

func (self *ConfigCommands) GetGlobalConfigValue(key string) string {
return self.gitConfig.GetGeneral("--global --get " + key)
}

func (self *ConfigCommands) SetLocalConfigValue(key string, value string) error {
return self.cmd.New(NewGitCmd("config").Arg("--local", key, value).ToArgv()).Run()
}

func (self *ConfigCommands) SetGlobalConfigValue(key string, value string) error {
return self.cmd.New(NewGitCmd("config").Arg("--global", key, value).ToArgv()).Run()
}

func (self *ConfigCommands) UnsetLocalConfigValue(key string) error {
return self.cmd.New(NewGitCmd("config").Arg("--local", "--unset", key).ToArgv()).Run()
}

func (self *ConfigCommands) UnsetGlobalConfigValue(key string) error {
return self.cmd.New(NewGitCmd("config").Arg("--global", "--unset", key).ToArgv()).Run()
}

func (self *ConfigCommands) listConfig(scope string) map[string]string {
cmdObj := self.cmd.New(NewGitCmd("config").Arg(scope, "--list", "--null").ToArgv()).DontLog()
stdout, _, err := cmdObj.RunWithOutputs()
if err != nil {
self.Log.Debugf("Error getting git config list for scope %s: %v", scope, err)
return map[string]string{}
}

return parseGitConfigList(stdout)
}

func parseGitConfigList(output string) map[string]string {
result := make(map[string]string)
entries := strings.Split(output, "\x00")
for _, entry := range entries {
if entry == "" {
continue
}
if parts := strings.SplitN(entry, "\n", 2); len(parts) == 2 {
result[parts[0]] = parts[1]
continue
}

if parts := strings.SplitN(entry, "=", 2); len(parts) == 2 {
result[parts[0]] = parts[1]
}
}
return result
}

func (self *ConfigCommands) DropConfigCache() {
self.gitConfig.DropCache()
}
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func buildGitCommon(deps commonDeps) *GitCommon {
}

gitCommon.repo = buildRepo()
gitCommon.config = NewConfigCommands(gitCommon.Common, gitConfig, gitCommon.repo)
gitCommon.config = NewConfigCommands(gitCommon.Common, gitConfig, gitCommon.repo, gitCommon.cmd)

getenv := deps.getenv
if getenv == nil {
Expand Down
11 changes: 6 additions & 5 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,12 @@ func (c *AppConfig) SaveGlobalUserConfig() {
// AppState stores data between runs of the app like when the last update check
// was performed and which other repos have been checked out
type AppState struct {
LastUpdateCheck int64
RecentRepos []string
StartupPopupVersion int
DidShowHunkStagingHint bool
LastVersion string // this is the last version the user was using, for the purpose of showing release notes
LastUpdateCheck int64
RecentRepos []string
StartupPopupVersion int
DidShowHunkStagingHint bool
LastVersion string // this is the last version the user was using, for the purpose of showing release notes
GitConfigExpandedSections []string `yaml:"gitConfigExpandedSections"`

// these are for shell commands typed in directly, not for custom commands in the lazygit config.
// For backwards compatibility we keep the old name in yaml files.
Expand Down
1 change: 1 addition & 0 deletions pkg/config/app_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ keybinding:
startSearch: /
optionMenu: <disabled>
optionMenu-alt1: '?'
gitConfig: ';'
select: <space>
goInto: <enter>
confirm: <enter>
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ type KeybindingUniversalConfig struct {
StartSearch string `yaml:"startSearch"`
OptionMenu string `yaml:"optionMenu"`
OptionMenuAlt1 string `yaml:"optionMenu-alt1"`
GitConfig string `yaml:"gitConfig"`
Select string `yaml:"select"`
GoInto string `yaml:"goInto"`
Confirm string `yaml:"confirm"`
Expand Down Expand Up @@ -909,6 +910,7 @@ func GetDefaultConfig() *UserConfig {
StartSearch: "/",
OptionMenu: "<disabled>",
OptionMenuAlt1: "?",
GitConfig: ";",
Select: "<space>",
GoInto: "<enter>",
Confirm: "<enter>",
Expand Down
9 changes: 7 additions & 2 deletions pkg/gui/context/menu_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type MenuContext struct {

*MenuViewModel
*ListContextTrait
extraKeybindings []*types.Binding
}

var _ types.IListContext = (*MenuContext)(nil)
Expand Down Expand Up @@ -216,14 +217,14 @@ func (self *MenuContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Bin
// allows assigning a keybinding to a menu item that overrides a non-essential binding such
// as 'j', 'k', 'H', 'L', etc. This is safe to do because the essential bindings such as
// confirm and return have already been removed from the menu items in this case.
return append(menuItemBindings, basicBindings...)
return append(append(menuItemBindings, self.extraKeybindings...), basicBindings...)
}

// For the keybindings menu we didn't remove the essential bindings from the menu items, because
// it is important to see all bindings (as a cheat sheet for what the keys are when the menu is
// not open). Therefore we want the essential bindings to have higher precedence than the menu
// item bindings.
return append(basicBindings, menuItemBindings...)
return append(append(basicBindings, menuItemBindings...), self.extraKeybindings...)
}

func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
Expand Down Expand Up @@ -261,3 +262,7 @@ func (self *MenuContext) FilterPrefix(tr *i18n.TranslationSet) string {

return self.FilteredListViewModel.FilterPrefix(tr)
}

func (self *MenuContext) SetExtraKeybindings(bindings []*types.Binding) {
self.extraKeybindings = bindings
}
2 changes: 2 additions & 0 deletions pkg/gui/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (gui *Gui) resetHelpersAndControllers() {
func() *status.StatusManager { return gui.statusManager },
modeHelper,
)
gitConfigHelper := helpers.NewGitConfigHelper(helperCommon)

gui.helpers = &helpers.Helpers{
Refs: refsHelper,
Expand All @@ -115,6 +116,7 @@ func (gui *Gui) resetHelpersAndControllers() {
Repos: reposHelper,
RecordDirectory: recordDirectoryHelper,
Update: helpers.NewUpdateHelper(helperCommon, gui.Updater),
GitConfig: gitConfigHelper,
Window: windowHelper,
View: viewHelper,
Refresh: refreshHelper,
Expand Down
16 changes: 16 additions & 0 deletions pkg/gui/controllers/global_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func NewGlobalController(

func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
return []*types.Binding{
{
Key: opts.GetKey(opts.Config.Universal.GitConfig),
Handler: opts.Guards.NoPopupPanel(self.c.Helpers().GitConfig.OpenMenu),
Description: self.c.Tr.GitConfigTitle,
DisplayOnScreen: true,
OpensMenu: true,
GetDisabledReason: self.gitConfigDisabledReason,
},
{
Key: opts.GetKey(opts.Config.Universal.ExecuteShellCommand),
Handler: self.shellCommand,
Expand Down Expand Up @@ -216,6 +224,14 @@ func (self *GlobalController) optionsMenuDisabledReason() *types.DisabledReason
return nil
}

func (self *GlobalController) gitConfigDisabledReason() *types.DisabledReason {
ctx := self.c.Context().Current()
if ctx.GetKind() == types.PERSISTENT_POPUP || ctx.GetKind() == types.TEMPORARY_POPUP {
return &types.DisabledReason{Text: ""}
}
return nil
}

func (self *GlobalController) createFilteringMenu() error {
return (&FilteringMenuAction{c: self.c}).Call()
}
Expand Down
Loading