1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

Support authors and tags in custom command suggestions preset

This commit is contained in:
Jesse Duffield 2023-06-07 10:15:49 +10:00
parent ced773ab18
commit a694c458dd
3 changed files with 15 additions and 5 deletions

View File

@ -101,7 +101,7 @@ These fields are applicable to all prompts.
The permitted suggestions fields are:
| _field_ | _description_ | _required_ |
|-----------------|----------------------|-|
| preset | Uses built-in logic to obtain the suggestions. One of 'files', 'branches', 'remotes', 'remoteBranches', 'refs' | no |
| preset | Uses built-in logic to obtain the suggestions. One of 'authors', 'branches', 'files', 'refs', 'remotes', 'remoteBranches', 'tags' | no |
| command | Command to run such that each line in the output becomes a suggestion. Mutually exclusive with 'preset' field. | no |
Here's an example of passing a preset:

View File

@ -157,6 +157,12 @@ func (self *SuggestionsHelper) getTagNames() []string {
})
}
func (self *SuggestionsHelper) GetTagsSuggestionsFunc() func(string) []*types.Suggestion {
tagNames := self.getTagNames()
return FuzzySearchFunc(tagNames)
}
func (self *SuggestionsHelper) GetRefsSuggestionsFunc() func(string) []*types.Suggestion {
remoteBranchNames := self.getRemoteBranchNames("/")
localBranchNames := self.getBranchNames()

View File

@ -161,16 +161,20 @@ func (self *HandlerCreator) getCommandSuggestionsFn(command string) (func(string
func (self *HandlerCreator) getPresetSuggestionsFn(preset string) (func(string) []*types.Suggestion, error) {
switch preset {
case "files":
return self.suggestionsHelper.GetFilePathSuggestionsFunc(), nil
case "authors":
return self.suggestionsHelper.GetAuthorsSuggestionsFunc(), nil
case "branches":
return self.suggestionsHelper.GetBranchNameSuggestionsFunc(), nil
case "files":
return self.suggestionsHelper.GetFilePathSuggestionsFunc(), nil
case "refs":
return self.suggestionsHelper.GetRefsSuggestionsFunc(), nil
case "remotes":
return self.suggestionsHelper.GetRemoteSuggestionsFunc(), nil
case "remoteBranches":
return self.suggestionsHelper.GetRemoteBranchesSuggestionsFunc("/"), nil
case "refs":
return self.suggestionsHelper.GetRefsSuggestionsFunc(), nil
case "tags":
return self.suggestionsHelper.GetTagsSuggestionsFunc(), nil
default:
return nil, fmt.Errorf("Unknown value for suggestionsPreset in custom command: %s. Valid values: files, branches, remotes, remoteBranches, refs", preset)
}