MCPcopy Index your code
hub / github.com/jesseduffield/lazygit / Call

Method Call

pkg/gui/controllers/shell_command_action.go:17–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15}
16
17func (self *ShellCommandAction) Call() error {
18 self.c.Prompt(types.PromptOpts{
19 Title: self.c.Tr.ShellCommand,
20 FindSuggestionsFunc: self.GetShellCommandsHistorySuggestionsFunc(),
21 AllowEditSuggestion: true,
22 PreserveWhitespace: true,
23 HandleConfirm: func(command string) error {
24 if self.shouldSaveCommand(command) {
25 self.c.GetAppState().ShellCommandsHistory = utils.Limit(
26 lo.Uniq(append([]string{command}, self.c.GetAppState().ShellCommandsHistory...)),
27 1000,
28 )
29 }
30
31 self.c.SaveAppStateAndLogError()
32
33 self.c.LogAction(self.c.Tr.Actions.CustomCommand)
34 return self.c.RunSubprocessAndRefresh(
35 self.c.OS().Cmd.NewShell(command, self.c.UserConfig().OS.ShellFunctionsFile),
36 )
37 },
38 HandleDeleteSuggestion: func(index int) error {
39 // index is the index in the _filtered_ list of suggestions, so we
40 // need to map it back to the full list. There's no really good way
41 // to do this, but fortunately we keep the items in the
42 // ShellCommandsHistory unique, which allows us to simply search
43 // for it by string.
44 item := self.c.Contexts().Suggestions.GetItems()[index].Value
45 fullIndex := lo.IndexOf(self.c.GetAppState().ShellCommandsHistory, item)
46 if fullIndex == -1 {
47 // Should never happen, but better be safe
48 return nil
49 }
50
51 self.c.GetAppState().ShellCommandsHistory = slices.Delete(
52 self.c.GetAppState().ShellCommandsHistory, fullIndex, fullIndex+1)
53 self.c.SaveAppStateAndLogError()
54 self.c.Contexts().Suggestions.RefreshSuggestions()
55 return nil
56 },
57 })
58
59 return nil
60}
61
62func (self *ShellCommandAction) GetShellCommandsHistorySuggestionsFunc() func(string) []*types.Suggestion {
63 return func(input string) []*types.Suggestion {

Callers

nothing calls this directly

Calls 15

shouldSaveCommandMethod · 0.95
LimitFunction · 0.92
UserConfigMethod · 0.80
GetItemsMethod · 0.80
RefreshSuggestionsMethod · 0.80
PromptMethod · 0.65
GetAppStateMethod · 0.65
LogActionMethod · 0.65
NewShellMethod · 0.65

Tested by

no test coverage detected