@@ -3,6 +3,7 @@ package controllers
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "path/filepath"
6
7
"strings"
7
8
8
9
"github.com/jesseduffield/gocui"
@@ -108,6 +109,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
108
109
Description : self .c .Tr .Actions .IgnoreExcludeFile ,
109
110
OpensMenu : true ,
110
111
},
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
+ },
111
118
{
112
119
Key : opts .GetKey (opts .Config .Files .RefreshFiles ),
113
120
Handler : self .refresh ,
@@ -650,6 +657,24 @@ func (self *FilesController) ignore(node *filetree.FileNode) error {
650
657
return self .ignoreOrExcludeFile (node , self .c .Tr .IgnoreTracked , self .c .Tr .IgnoreTrackedPrompt , self .c .Tr .Actions .IgnoreExcludeFile , self .c .Git ().WorkingTree .Ignore )
651
658
}
652
659
660
+ func (self * FilesController ) ignoreExtension (node * filetree.FileNode ) error {
661
+ if node .GetPath () == ".gitignore" {
662
+ return errors .New (self .c .Tr .Actions .IgnoreFileErr )
663
+ }
664
+
665
+ path := node .GetPath ()
666
+ ext := filepath .Ext (path )
667
+ if ext == "" {
668
+ return fmt .Errorf ("No file extension to ignore" )
669
+ }
670
+
671
+ pattern := "*" + ext
672
+
673
+ return self .ignoreOrExcludeFile (node , self .c .Tr .IgnoreTracked , self .c .Tr .IgnoreTrackedPrompt , self .c .Tr .Actions .IgnoreExcludeFile , func (string ) error {
674
+ return self .c .Git ().WorkingTree .Ignore (pattern )
675
+ })
676
+ }
677
+
653
678
func (self * FilesController ) exclude (node * filetree.FileNode ) error {
654
679
if node .GetPath () == ".gitignore" {
655
680
return errors .New (self .c .Tr .Actions .ExcludeGitIgnoreErr )
@@ -672,6 +697,16 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
672
697
},
673
698
Key : 'i' ,
674
699
},
700
+ {
701
+ LabelColumns : []string {self .c .Tr .IgnoreFileExtension },
702
+ OnPress : func () error {
703
+ if err := self .ignoreExtension (node ); err != nil {
704
+ return err
705
+ }
706
+ return nil
707
+ },
708
+ Key : 'I' ,
709
+ },
675
710
{
676
711
LabelColumns : []string {self .c .Tr .ExcludeFile },
677
712
OnPress : func () error {
0 commit comments