From 36f4fe0c67aabcb5b7ba2e18085a956ffb95dbf6 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Thu, 13 Mar 2025 00:01:15 +0100 Subject: [PATCH 1/2] Implement "Ignore by file extension" command That works exactly like the "ignore" command But instead of ignoring a file it ignores *. of the selected file --- pkg/config/user_config.go | 2 ++ pkg/gui/controllers/files_controller.go | 34 +++++++++++++++++++++++++ pkg/i18n/english.go | 2 ++ 3 files changed, 38 insertions(+) diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 3cb945a8d02..86e8b4c96d3 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -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: "", 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 5f4a3bae0e2..9689a17acbb 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -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 { diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 73571d7eee6..799c6654acf 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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`, From c86bb5bab523b451e30e5be94b9a6553c65d10aa Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Thu, 13 Mar 2025 00:08:57 +0100 Subject: [PATCH 2/2] Update cheatsheets --- docs/Config.md | 1 + docs/keybindings/Keybindings_en.md | 1 + docs/keybindings/Keybindings_ja.md | 1 + docs/keybindings/Keybindings_ko.md | 1 + docs/keybindings/Keybindings_nl.md | 1 + docs/keybindings/Keybindings_pl.md | 1 + docs/keybindings/Keybindings_pt.md | 1 + docs/keybindings/Keybindings_ru.md | 1 + docs/keybindings/Keybindings_zh-CN.md | 1 + docs/keybindings/Keybindings_zh-TW.md | 1 + schema/config.json | 4 ++++ 11 files changed, 14 insertions(+) diff --git a/docs/Config.md b/docs/Config.md index 0a8c9d1e78b..89bfe8a5bf1 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -557,6 +557,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 c24bc736b15..b2ad3786e47 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -138,6 +138,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` 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 9d583a270c2..eb5085073a9 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -210,6 +210,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` e `` | Edit | 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 6ea53f3cee9..708883a6ef7 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -351,6 +351,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` 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 1e3bd722d5b..deb99eb2069 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 ab95bc0f953..85d2312ea72 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -217,6 +217,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita, | `` 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 b098095193a..395224362a2 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 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_ru.md b/docs/keybindings/Keybindings_ru.md index eeb73c3cb59..9eb9df74648 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -345,6 +345,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` 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 de1cbb659a6..fe628c5e7cb 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -216,6 +216,7 @@ _图例:`` 意味着ctrl+b, `意味着Alt+b, `B` 意味着shift+b_ | `` 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 f6abf403a1d..a5e8e147951 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -312,6 +312,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` 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/schema/config.json b/schema/config.json index a4b4d0f43f0..db967bf3a42 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1016,6 +1016,10 @@ "type": "string", "default": "i" }, + "ignoreFileExtension": { + "type": "string", + "default": "I" + }, "refreshFiles": { "type": "string", "default": "r"