mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55: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"`
|
FindBaseCommitForFixup string `yaml:"findBaseCommitForFixup"`
|
||||||
ConfirmDiscard string `yaml:"confirmDiscard"`
|
ConfirmDiscard string `yaml:"confirmDiscard"`
|
||||||
IgnoreFile string `yaml:"ignoreFile"`
|
IgnoreFile string `yaml:"ignoreFile"`
|
||||||
|
IgnoreFileExtension string `yaml:"ignoreFileExtension"`
|
||||||
RefreshFiles string `yaml:"refreshFiles"`
|
RefreshFiles string `yaml:"refreshFiles"`
|
||||||
StashAllChanges string `yaml:"stashAllChanges"`
|
StashAllChanges string `yaml:"stashAllChanges"`
|
||||||
ViewStashOptions string `yaml:"viewStashOptions"`
|
ViewStashOptions string `yaml:"viewStashOptions"`
|
||||||
|
@ -928,6 +929,7 @@ func GetDefaultConfig() *UserConfig {
|
||||||
CommitChangesWithEditor: "C",
|
CommitChangesWithEditor: "C",
|
||||||
FindBaseCommitForFixup: "<c-f>",
|
FindBaseCommitForFixup: "<c-f>",
|
||||||
IgnoreFile: "i",
|
IgnoreFile: "i",
|
||||||
|
IgnoreFileExtension: "I",
|
||||||
RefreshFiles: "r",
|
RefreshFiles: "r",
|
||||||
StashAllChanges: "s",
|
StashAllChanges: "s",
|
||||||
ViewStashOptions: "S",
|
ViewStashOptions: "S",
|
||||||
|
|
|
@ -109,6 +109,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
|
||||||
Description: self.c.Tr.Actions.IgnoreExcludeFile,
|
Description: self.c.Tr.Actions.IgnoreExcludeFile,
|
||||||
OpensMenu: true,
|
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),
|
Key: opts.GetKey(opts.Config.Files.RefreshFiles),
|
||||||
Handler: self.refresh,
|
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)
|
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 {
|
func (self *FilesController) exclude(node *filetree.FileNode) error {
|
||||||
if node.GetPath() == ".gitignore" {
|
if node.GetPath() == ".gitignore" {
|
||||||
return errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr)
|
return errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr)
|
||||||
|
@ -679,6 +703,16 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
|
||||||
},
|
},
|
||||||
Key: 'i',
|
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},
|
LabelColumns: []string{self.c.Tr.ExcludeFile},
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
|
|
|
@ -252,6 +252,7 @@ type TranslationSet struct {
|
||||||
OpenFileTooltip string
|
OpenFileTooltip string
|
||||||
OpenInEditor string
|
OpenInEditor string
|
||||||
IgnoreFile string
|
IgnoreFile string
|
||||||
|
IgnoreFileExtension string
|
||||||
ExcludeFile string
|
ExcludeFile string
|
||||||
RefreshFiles string
|
RefreshFiles string
|
||||||
Merge string
|
Merge string
|
||||||
|
@ -1291,6 +1292,7 @@ func EnglishTranslationSet() *TranslationSet {
|
||||||
OpenFileTooltip: "Open file in default application.",
|
OpenFileTooltip: "Open file in default application.",
|
||||||
OpenInEditor: "Open in editor",
|
OpenInEditor: "Open in editor",
|
||||||
IgnoreFile: `Add to .gitignore`,
|
IgnoreFile: `Add to .gitignore`,
|
||||||
|
IgnoreFileExtension: `Add extension to .gitignore`,
|
||||||
ExcludeFile: `Add to .git/info/exclude`,
|
ExcludeFile: `Add to .git/info/exclude`,
|
||||||
RefreshFiles: `Refresh files`,
|
RefreshFiles: `Refresh files`,
|
||||||
Merge: `Merge`,
|
Merge: `Merge`,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue