Skip to content

Commit 36f4fe0

Browse files
author
PhatPhuckDave
committed
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
1 parent c55062f commit 36f4fe0

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Diff for: pkg/config/user_config.go

+2
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ type KeybindingFilesConfig struct {
455455
FindBaseCommitForFixup string `yaml:"findBaseCommitForFixup"`
456456
ConfirmDiscard string `yaml:"confirmDiscard"`
457457
IgnoreFile string `yaml:"ignoreFile"`
458+
IgnoreFileExtension string `yaml:"ignoreFileExtension"`
458459
RefreshFiles string `yaml:"refreshFiles"`
459460
StashAllChanges string `yaml:"stashAllChanges"`
460461
ViewStashOptions string `yaml:"viewStashOptions"`
@@ -928,6 +929,7 @@ func GetDefaultConfig() *UserConfig {
928929
CommitChangesWithEditor: "C",
929930
FindBaseCommitForFixup: "<c-f>",
930931
IgnoreFile: "i",
932+
IgnoreFileExtension: "I",
931933
RefreshFiles: "r",
932934
StashAllChanges: "s",
933935
ViewStashOptions: "S",

Diff for: pkg/gui/controllers/files_controller.go

+34
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
109109
Description: self.c.Tr.Actions.IgnoreExcludeFile,
110110
OpensMenu: true,
111111
},
112+
{
113+
Key: opts.GetKey(opts.Config.Files.IgnoreFileExtension),
114+
Handler: self.withItem(self.ignoreExtension),
115+
GetDisabledReason: self.require(self.singleItemSelected()),
116+
Description: self.c.Tr.IgnoreFileExtension,
117+
},
112118
{
113119
Key: opts.GetKey(opts.Config.Files.RefreshFiles),
114120
Handler: self.refresh,
@@ -657,6 +663,24 @@ func (self *FilesController) ignore(node *filetree.FileNode) error {
657663
return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, self.c.Git().WorkingTree.Ignore)
658664
}
659665

666+
func (self *FilesController) ignoreExtension(node *filetree.FileNode) error {
667+
if node.GetPath() == ".gitignore" {
668+
return errors.New(self.c.Tr.Actions.IgnoreFileErr)
669+
}
670+
671+
path := node.GetPath()
672+
ext := filepath.Ext(path)
673+
if ext == "" {
674+
return fmt.Errorf("No file extension to ignore")
675+
}
676+
677+
pattern := "*" + ext
678+
679+
return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, func(string) error {
680+
return self.c.Git().WorkingTree.Ignore(pattern)
681+
})
682+
}
683+
660684
func (self *FilesController) exclude(node *filetree.FileNode) error {
661685
if node.GetPath() == ".gitignore" {
662686
return errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr)
@@ -679,6 +703,16 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
679703
},
680704
Key: 'i',
681705
},
706+
{
707+
LabelColumns: []string{self.c.Tr.IgnoreFileExtension},
708+
OnPress: func() error {
709+
if err := self.ignoreExtension(node); err != nil {
710+
return err
711+
}
712+
return nil
713+
},
714+
Key: 'I',
715+
},
682716
{
683717
LabelColumns: []string{self.c.Tr.ExcludeFile},
684718
OnPress: func() error {

Diff for: pkg/i18n/english.go

+2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ type TranslationSet struct {
252252
OpenFileTooltip string
253253
OpenInEditor string
254254
IgnoreFile string
255+
IgnoreFileExtension string
255256
ExcludeFile string
256257
RefreshFiles string
257258
Merge string
@@ -1291,6 +1292,7 @@ func EnglishTranslationSet() *TranslationSet {
12911292
OpenFileTooltip: "Open file in default application.",
12921293
OpenInEditor: "Open in editor",
12931294
IgnoreFile: `Add to .gitignore`,
1295+
IgnoreFileExtension: `Add extension to .gitignore`,
12941296
ExcludeFile: `Add to .git/info/exclude`,
12951297
RefreshFiles: `Refresh files`,
12961298
Merge: `Merge`,

0 commit comments

Comments
 (0)