1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

add menu keybindings for various things

This commit is contained in:
Jesse Duffield
2022-03-27 17:19:31 +11:00
parent e94312b664
commit 3e5d4b2c74
10 changed files with 69 additions and 12 deletions

View File

@ -103,24 +103,28 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
OnPress: func() error { OnPress: func() error {
return self.copyCommitSHAToClipboard(commit) return self.copyCommitSHAToClipboard(commit)
}, },
Key: 's',
}, },
{ {
DisplayString: self.c.Tr.LcCommitURL, DisplayString: self.c.Tr.LcCommitURL,
OnPress: func() error { OnPress: func() error {
return self.copyCommitURLToClipboard(commit) return self.copyCommitURLToClipboard(commit)
}, },
Key: 'u',
}, },
{ {
DisplayString: self.c.Tr.LcCommitDiff, DisplayString: self.c.Tr.LcCommitDiff,
OnPress: func() error { OnPress: func() error {
return self.copyCommitDiffToClipboard(commit) return self.copyCommitDiffToClipboard(commit)
}, },
Key: 'd',
}, },
{ {
DisplayString: self.c.Tr.LcCommitMessage, DisplayString: self.c.Tr.LcCommitMessage,
OnPress: func() error { OnPress: func() error {
return self.copyCommitMessageToClipboard(commit) return self.copyCommitMessageToClipboard(commit)
}, },
Key: 'm',
}, },
}, },
}) })

View File

@ -76,6 +76,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
return self.afterMark(selectCurrentAfter, waitToReselect) return self.afterMark(selectCurrentAfter, waitToReselect)
}, },
Key: 'b',
}, },
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.OldTerm()), DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.OldTerm()),
@ -87,6 +88,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
return self.afterMark(selectCurrentAfter, waitToReselect) return self.afterMark(selectCurrentAfter, waitToReselect)
}, },
Key: 'g',
}, },
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Skip, commit.ShortSha()), DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Skip, commit.ShortSha()),
@ -98,12 +100,14 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
return self.afterMark(selectCurrentAfter, waitToReselect) return self.afterMark(selectCurrentAfter, waitToReselect)
}, },
Key: 's',
}, },
{ {
DisplayString: self.c.Tr.Bisect.ResetOption, DisplayString: self.c.Tr.Bisect.ResetOption,
OnPress: func() error { OnPress: func() error {
return self.helpers.Bisect.Reset() return self.helpers.Bisect.Reset()
}, },
Key: 'r',
}, },
} }
@ -131,6 +135,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
return self.helpers.Bisect.PostBisectCommandRefresh() return self.helpers.Bisect.PostBisectCommandRefresh()
}, },
Key: 'b',
}, },
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()), DisplayString: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()),
@ -146,6 +151,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
return self.helpers.Bisect.PostBisectCommandRefresh() return self.helpers.Bisect.PostBisectCommandRefresh()
}, },
Key: 'g',
}, },
}, },
}) })

View File

@ -562,6 +562,7 @@ func (self *FilesController) createStashMenu() error {
self.c.LogAction(self.c.Tr.Actions.StashAllChanges) self.c.LogAction(self.c.Tr.Actions.StashAllChanges)
return self.handleStashSave(self.git.Stash.Save) return self.handleStashSave(self.git.Stash.Save)
}, },
Key: 's',
}, },
{ {
DisplayString: self.c.Tr.LcStashStagedChanges, DisplayString: self.c.Tr.LcStashStagedChanges,
@ -569,6 +570,7 @@ func (self *FilesController) createStashMenu() error {
self.c.LogAction(self.c.Tr.Actions.StashStagedChanges) self.c.LogAction(self.c.Tr.Actions.StashStagedChanges)
return self.handleStashSave(self.git.Stash.SaveStagedChanges) return self.handleStashSave(self.git.Stash.SaveStagedChanges)
}, },
Key: 'S',
}, },
}, },
}) })

View File

@ -51,6 +51,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
} }
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'd',
}, },
} }
@ -65,6 +66,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'u',
}) })
} }
} else { } else {
@ -93,6 +95,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
} }
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'd',
}, },
} }
@ -107,6 +110,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'u',
}) })
} }
} }

View File

@ -72,18 +72,22 @@ func (self *GitFlowController) handleCreateGitFlowMenu(branch *models.Branch) er
{ {
DisplayString: "start feature", DisplayString: "start feature",
OnPress: startHandler("feature"), OnPress: startHandler("feature"),
Key: 'f',
}, },
{ {
DisplayString: "start hotfix", DisplayString: "start hotfix",
OnPress: startHandler("hotfix"), OnPress: startHandler("hotfix"),
Key: 'h',
}, },
{ {
DisplayString: "start bugfix", DisplayString: "start bugfix",
OnPress: startHandler("bugfix"), OnPress: startHandler("bugfix"),
Key: 'b',
}, },
{ {
DisplayString: "start release", DisplayString: "start release",
OnPress: startHandler("release"), OnPress: startHandler("release"),
Key: 'r',
}, },
}, },
}) })

View File

@ -46,18 +46,29 @@ const (
) )
func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
options := []string{REBASE_OPTION_CONTINUE, REBASE_OPTION_ABORT} type optionAndKey struct {
option string
if self.git.Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { key types.Key
options = append(options, REBASE_OPTION_SKIP)
} }
menuItems := slices.Map(options, func(option string) *types.MenuItem { options := []optionAndKey{
{option: REBASE_OPTION_CONTINUE, key: 'c'},
{option: REBASE_OPTION_ABORT, key: 'a'},
}
if self.git.Status.WorkingTreeState() == enums.REBASE_MODE_REBASING {
options = append(options, optionAndKey{
option: REBASE_OPTION_SKIP, key: 's',
})
}
menuItems := slices.Map(options, func(row optionAndKey) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayString: option, DisplayString: row.option,
OnPress: func() error { OnPress: func() error {
return self.genericMergeCommand(option) return self.genericMergeCommand(row.option)
}, },
Key: row.key,
} }
}) })

View File

@ -134,17 +134,27 @@ func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string
} }
func (self *RefsHelper) CreateGitResetMenu(ref string) error { func (self *RefsHelper) CreateGitResetMenu(ref string) error {
strengths := []string{"soft", "mixed", "hard"} type strengthWithKey struct {
menuItems := slices.Map(strengths, func(strength string) *types.MenuItem { strength string
key types.Key
}
strengths := []strengthWithKey{
{strength: "soft", key: 's'},
{strength: "mixed", key: 'm'},
{strength: "hard", key: 'h'},
}
menuItems := slices.Map(strengths, func(row strengthWithKey) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayStrings: []string{ DisplayStrings: []string{
fmt.Sprintf("%s reset", strength), fmt.Sprintf("%s reset", row.strength),
style.FgRed.Sprintf("reset --%s %s", strength, ref), style.FgRed.Sprintf("reset --%s %s", row.strength, ref),
}, },
OnPress: func() error { OnPress: func() error {
self.c.LogAction("Reset") self.c.LogAction("Reset")
return self.ResetToRef(ref, strength, []string{}) return self.ResetToRef(ref, row.strength, []string{})
}, },
Key: row.key,
} }
}) })

View File

@ -158,6 +158,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}}) return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
}) })
}, },
Key: 'i',
}, },
{ {
DisplayStrings: []string{self.c.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(self.git.Submodule.BulkUpdateCmdObj().ToString())}, DisplayStrings: []string{self.c.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(self.git.Submodule.BulkUpdateCmdObj().ToString())},
@ -171,6 +172,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}}) return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
}) })
}, },
Key: 'u',
}, },
{ {
DisplayStrings: []string{self.c.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(self.git.Submodule.BulkDeinitCmdObj().ToString())}, DisplayStrings: []string{self.c.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(self.git.Submodule.BulkDeinitCmdObj().ToString())},
@ -184,6 +186,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}}) return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUBMODULES}})
}) })
}, },
Key: 'd',
}, },
}, },
}) })

View File

@ -31,6 +31,7 @@ func (self *FilesController) createResetMenu() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'D',
}, },
{ {
DisplayStrings: []string{ DisplayStrings: []string{
@ -45,6 +46,7 @@ func (self *FilesController) createResetMenu() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'u',
}, },
{ {
DisplayStrings: []string{ DisplayStrings: []string{
@ -59,6 +61,7 @@ func (self *FilesController) createResetMenu() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'c',
}, },
{ {
DisplayStrings: []string{ DisplayStrings: []string{
@ -73,6 +76,7 @@ func (self *FilesController) createResetMenu() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 's',
}, },
{ {
DisplayStrings: []string{ DisplayStrings: []string{
@ -87,6 +91,7 @@ func (self *FilesController) createResetMenu() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'm',
}, },
{ {
DisplayStrings: []string{ DisplayStrings: []string{
@ -101,6 +106,7 @@ func (self *FilesController) createResetMenu() error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
}, },
Key: 'h',
}, },
} }

View File

@ -17,14 +17,17 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
{ {
DisplayString: "reset patch", DisplayString: "reset patch",
OnPress: gui.handleResetPatch, OnPress: gui.handleResetPatch,
Key: 'c',
}, },
{ {
DisplayString: "apply patch", DisplayString: "apply patch",
OnPress: func() error { return gui.handleApplyPatch(false) }, OnPress: func() error { return gui.handleApplyPatch(false) },
Key: 'a',
}, },
{ {
DisplayString: "apply patch in reverse", DisplayString: "apply patch in reverse",
OnPress: func() error { return gui.handleApplyPatch(true) }, OnPress: func() error { return gui.handleApplyPatch(true) },
Key: 'r',
}, },
} }
@ -33,14 +36,17 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
{ {
DisplayString: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchManager.To), DisplayString: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchManager.To),
OnPress: gui.handleDeletePatchFromCommit, OnPress: gui.handleDeletePatchFromCommit,
Key: 'd',
}, },
{ {
DisplayString: "move patch out into index", DisplayString: "move patch out into index",
OnPress: gui.handleMovePatchIntoWorkingTree, OnPress: gui.handleMovePatchIntoWorkingTree,
Key: 'i',
}, },
{ {
DisplayString: "move patch into new commit", DisplayString: "move patch into new commit",
OnPress: gui.handlePullPatchIntoNewCommit, OnPress: gui.handlePullPatchIntoNewCommit,
Key: 'n',
}, },
}...) }...)
@ -55,6 +61,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
{ {
DisplayString: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha), DisplayString: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha),
OnPress: gui.handleMovePatchToSelectedCommit, OnPress: gui.handleMovePatchToSelectedCommit,
Key: 'm',
}, },
}, menuItems[1:]..., }, menuItems[1:]...,
)..., )...,