Replies: 2 comments
-
There's a check missing here: Line 170 in 56b43be I think that's about it |
Beta Was this translation helpful? Give feedback.
-
@RamiAwar Apart from the check for omitting First: new snippet files are created based on command description, not time based. // Save saves the snippets to toml file.
func (snippets *Snippets) Save() error {
var snippetFile string
var newSnippets Snippets
for _, snippet := range snippets.Snippets {
if snippet.Filename == "" {
snippetFile = config.Conf.General.SnippetDirs[0] + fmt.Sprintf("%s.toml", strings.ToLower(sanitize.BaseName(snippet.Description)))
newSnippets.Snippets = append(newSnippets.Snippets, snippet)
} else if snippet.Filename == config.Conf.General.SnippetFile {
snippetFile = config.Conf.General.SnippetFile
newSnippets.Snippets = append(newSnippets.Snippets, snippet)
}
}
... Secondly, new snippet file created this way (using directory and omitting snippet file attribute) will duplicate previously added commands. Here's an example: SnippetDirs = ["~/.config/pet/"]
SnippetFile = "" fw13 :: ~/Documents/pet ‹feat-syspath*› » go run main.go new
Command> "~/.config/pet/", SnippetFile omitted
Description> Test #1
fw13 :: ~/Documents/pet ‹feat-syspath*› » go run main.go edit
fw13 :: ~/Documents/pet ‹feat-syspath*› » cat ~/.config/pet/test-1.toml
1 │
2 │ [[Snippets]]
3 │ Description = "Test #1"
4 │ Filename = ""
5 │ Output = ""
6 │ Tag = []
7 │ command = "\"~/.config/pet/\", SnippetFile omitted" This is fine. Similarly, creating another snippet and we get: fw13 :: ~/Documents/pet ‹feat-syspath*› » cat ~/.config/pet/test-2.toml
1 │
2 │ [[Snippets]]
3 │ Description = "Test #1"
4 │ Filename = "/home/csessh/.config/pet/test-1.toml"
5 │ Output = ""
6 │ Tag = []
7 │ command = "\"~/.config/pet/\", SnippetFile omitted"
8 │
9 │ [[Snippets]]
10 │ Description = "test #2"
11 │ Filename = ""
12 │ Output = ""
13 │ Tag = []
14 │ command = "relative path, no snippetfile"
Test 1 command shouldn't be present in |
Beta Was this translation helpful? Give feedback.
-
While doing some tests for #320, this came up:
Pet raised exception when
SnippetFile
attribute is omitted (as per https://github.com/knqyf263/pet/blob/main/README.md#multi-directory-and-multi-file-setup)Here's how to reproduce:
1- Fresh install
2- Config file:
3-
Pet new
Expected result:
Actual result:
Note: This yields the same result
Beta Was this translation helpful? Give feedback.
All reactions