Implement "Ignore by file extension" command

That works exactly like the "ignore" command
But instead of ignoring a file it ignores *.<extension> of the selected
file
This commit is contained in:
PhatPhuckDave 2025-03-13 00:01:15 +01:00
parent c55062fe86
commit 36f4fe0c67
3 changed files with 38 additions and 0 deletions

View file

@ -455,6 +455,7 @@ type KeybindingFilesConfig struct {
FindBaseCommitForFixup string `yaml:"findBaseCommitForFixup"`
ConfirmDiscard string `yaml:"confirmDiscard"`
IgnoreFile string `yaml:"ignoreFile"`
IgnoreFileExtension string `yaml:"ignoreFileExtension"`
RefreshFiles string `yaml:"refreshFiles"`
StashAllChanges string `yaml:"stashAllChanges"`
ViewStashOptions string `yaml:"viewStashOptions"`
@ -928,6 +929,7 @@ func GetDefaultConfig() *UserConfig {
CommitChangesWithEditor: "C",
FindBaseCommitForFixup: "<c-f>",
IgnoreFile: "i",
IgnoreFileExtension: "I",
RefreshFiles: "r",
StashAllChanges: "s",
ViewStashOptions: "S",

View file

@ -109,6 +109,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
Description: self.c.Tr.Actions.IgnoreExcludeFile,
OpensMenu: true,
},
{
Key: opts.GetKey(opts.Config.Files.IgnoreFileExtension),
Handler: self.withItem(self.ignoreExtension),
GetDisabledReason: self.require(self.singleItemSelected()),
Description: self.c.Tr.IgnoreFileExtension,
},
{
Key: opts.GetKey(opts.Config.Files.RefreshFiles),
Handler: self.refresh,
@ -657,6 +663,24 @@ func (self *FilesController) ignore(node *filetree.FileNode) error {
return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, self.c.Git().WorkingTree.Ignore)
}
func (self *FilesController) ignoreExtension(node *filetree.FileNode) error {
if node.GetPath() == ".gitignore" {
return errors.New(self.c.Tr.Actions.IgnoreFileErr)
}
path := node.GetPath()
ext := filepath.Ext(path)
if ext == "" {
return fmt.Errorf("No file extension to ignore")
}
pattern := "*" + ext
return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, func(string) error {
return self.c.Git().WorkingTree.Ignore(pattern)
})
}
func (self *FilesController) exclude(node *filetree.FileNode) error {
if node.GetPath() == ".gitignore" {
return errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr)
@ -679,6 +703,16 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
},
Key: 'i',
},
{
LabelColumns: []string{self.c.Tr.IgnoreFileExtension},
OnPress: func() error {
if err := self.ignoreExtension(node); err != nil {
return err
}
return nil
},
Key: 'I',
},
{
LabelColumns: []string{self.c.Tr.ExcludeFile},
OnPress: func() error {

View file

@ -252,6 +252,7 @@ type TranslationSet struct {
OpenFileTooltip string
OpenInEditor string
IgnoreFile string
IgnoreFileExtension string
ExcludeFile string
RefreshFiles string
Merge string
@ -1291,6 +1292,7 @@ func EnglishTranslationSet() *TranslationSet {
OpenFileTooltip: "Open file in default application.",
OpenInEditor: "Open in editor",
IgnoreFile: `Add to .gitignore`,
IgnoreFileExtension: `Add extension to .gitignore`,
ExcludeFile: `Add to .git/info/exclude`,
RefreshFiles: `Refresh files`,
Merge: `Merge`,