()
| 15 | } |
| 16 | |
| 17 | func (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 | |
| 62 | func (self *ShellCommandAction) GetShellCommandsHistorySuggestionsFunc() func(string) []*types.Suggestion { |
| 63 | return func(input string) []*types.Suggestion { |
nothing calls this directly
no test coverage detected