diff --git a/docs/Config.md b/docs/Config.md index d401e833c..0994ffb65 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -567,6 +567,7 @@ keybinding: findBaseCommitForFixup: confirmDiscard: x ignoreFile: i + ignoreFileExtension: I refreshFiles: r stashAllChanges: s viewStashOptions: S diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index f6c622b07..d328ffea6 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -144,6 +144,7 @@ Note that this disregards the selection, the new branch is always created either | `` e `` | Edit | Open file in external editor. | | `` o `` | Open file | Open file in default application. | | `` i `` | Ignore or exclude file | | +| `` I `` | Add extension to .gitignore | | | `` r `` | Refresh files | | | `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. | | `` S `` | View stash options | View stash options (e.g. stash all, stash staged, stash unstaged). | diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 199825c9f..63bb9500c 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -231,6 +231,7 @@ Note that this disregards the selection, the new branch is always created either | `` e `` | 編集 | Open file in external editor. | | `` o `` | ファイルを開く | Open file in default application. | | `` i `` | ファイルをignore | | +| `` I `` | Add extension to .gitignore | | | `` r `` | ファイルをリフレッシュ | | | `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. | | `` S `` | View stash options | View stash options (e.g. stash all, stash staged, stash unstaged). | diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index f5c18a964..b93af0a1f 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -385,6 +385,7 @@ Note that this disregards the selection, the new branch is always created either | `` e `` | Edit | Open file in external editor. | | `` o `` | 파일 닫기 | Open file in default application. | | `` i `` | Ignore file | | +| `` I `` | Add extension to .gitignore | | | `` r `` | 파일 새로고침 | | | `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. | | `` S `` | Stash 옵션 보기 | View stash options (e.g. stash all, stash staged, stash unstaged). | diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index b0b23d254..96fc7105b 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -67,6 +67,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` e `` | Edit | Open file in external editor. | | `` o `` | Open bestand | Open file in default application. | | `` i `` | Ignore or exclude file | | +| `` I `` | Add extension to .gitignore | | | `` r `` | Refresh bestanden | | | `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. | | `` S `` | Bekijk stash opties | View stash options (e.g. stash all, stash staged, stash unstaged). | diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 88a886a35..7e34f8849 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -237,6 +237,7 @@ Note that this disregards the selection, the new branch is always created either | `` e `` | Edytuj | Otwórz plik w zewnętrznym edytorze. | | `` o `` | Otwórz plik | Otwórz plik w domyślnej aplikacji. | | `` i `` | Ignoruj lub wyklucz plik | | +| `` I `` | Add extension to .gitignore | | | `` r `` | Odśwież pliki | | | `` s `` | Schowaj | Schowaj wszystkie zmiany. Dla innych wariantów schowania, użyj klawisza wyświetlania opcji schowka. | | `` S `` | Wyświetl opcje schowka | Wyświetl opcje schowka (np. schowaj wszystko, schowaj zatwierdzone, schowaj niezatwierdzone). | diff --git a/docs/keybindings/Keybindings_pt.md b/docs/keybindings/Keybindings_pt.md index fc9510e86..8427e7473 100644 --- a/docs/keybindings/Keybindings_pt.md +++ b/docs/keybindings/Keybindings_pt.md @@ -69,6 +69,7 @@ Veja a documentação: | `` e `` | Editar | Abrir arquivo no editor externo. | | `` o `` | Abrir arquivo | Abrir arquivo no aplicativo padrão. | | `` i `` | Ignore or exclude file | | +| `` I `` | Add extension to .gitignore | | | `` r `` | Atualizar arquivos | | | `` s `` | Stash | Stash todas as alterações. Para outras variações de armazenamento, use a fixação de teclas de armazenamento. | | `` S `` | Ver opções de stash | Ver opções de stash (por exemplo, trash all, stash staged, stash unsttued). | diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index 35ce45beb..6cb80ff46 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -378,6 +378,7 @@ Note that this disregards the selection, the new branch is always created either | `` e `` | Edit | Open file in external editor. | | `` o `` | Открыть файл | Open file in default application. | | `` i `` | Игнорировать или исключить файл | | +| `` I `` | Add extension to .gitignore | | | `` r `` | Обновить файлы | | | `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. | | `` S `` | Просмотреть параметры хранилища | View stash options (e.g. stash all, stash staged, stash unstaged). | diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index eb09f4ca0..2178891ac 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -205,6 +205,7 @@ Note that this disregards the selection, the new branch is always created either | `` e `` | 编辑 | 使用外部编辑器打开文件 | | `` o `` | 打开文件 | 使用默认程序打开该文件 | | `` i `` | 忽略文件 | | +| `` I `` | Add extension to .gitignore | | | `` r `` | 刷新文件 | | | `` s `` | 贮藏 | 贮藏所有变更.若要使用其他贮藏变体,请使用查看贮藏选项快捷键 | | `` S `` | 查看贮藏选项 | 查看贮藏选项(例如:贮藏所有、贮藏已暂存变更、贮藏未暂存变更) | diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index 5715b0230..bcb4cb381 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -337,6 +337,7 @@ Note that this disregards the selection, the new branch is always created either | `` e `` | 編輯 | 使用外部編輯器開啟 | | `` o `` | 開啟檔案 | 使用預設軟體開啟 | | `` i `` | 忽略或排除檔案 | | +| `` I `` | Add extension to .gitignore | | | `` r `` | 重新整理檔案 | | | `` s `` | 收藏 | Stash all changes. For other variations of stashing, use the view stash options keybinding. | | `` S `` | 檢視收藏選項 | View stash options (e.g. stash all, stash staged, stash unstaged). | diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 2becab4c9..18d032d6d 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -456,6 +456,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"` @@ -930,6 +931,7 @@ func GetDefaultConfig() *UserConfig { CommitChangesWithEditor: "C", FindBaseCommitForFixup: "", IgnoreFile: "i", + IgnoreFileExtension: "I", RefreshFiles: "r", StashAllChanges: "s", ViewStashOptions: "S", diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 6df28a523..b4f1f2321 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -110,6 +110,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, @@ -718,6 +724,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) @@ -740,6 +764,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 { diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index e7311e021..0d9ffe401 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -272,6 +272,7 @@ type TranslationSet struct { OpenFileTooltip string OpenInEditor string IgnoreFile string + IgnoreFileExtension string ExcludeFile string RefreshFiles string FocusMainView string @@ -1351,6 +1352,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`, FocusMainView: "Focus main view", diff --git a/schema/config.json b/schema/config.json index 295dc2ceb..6f013a8c0 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1031,6 +1031,10 @@ "type": "string", "default": "i" }, + "ignoreFileExtension": { + "type": "string", + "default": "I" + }, "refreshFiles": { "type": "string", "default": "r"