mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
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:
parent
c55062fe86
commit
36f4fe0c67
3 changed files with 38 additions and 0 deletions
|
@ -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",
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue