Open cderv opened 2 months ago
Hmm interesting, wonder why we don't clean up the args when using the generic command from conf.
Will look into this one. Tricky to change tho as it might break for people depending on it
I can confirm similar behaviour on MacOS - I have VSCode configured for edit and it's opening +0
file as well:
This seems to be "working as designed", i.e. when added a print statement, it shows clearly that +0
came intentionally:
go run . configure
code +0 /Users/jhartman/.config/pet/config.toml
This must have been thought as an aid to move the cursor to the end of the snippets file, +3 lines after the last line, see:
func new(cmd *cobra.Command, args []string) (err error) {
...
return createAndEditSnippet(newSnippet, snippets, lineCount+3)
...
As per vi
man:
vi Command-Line Options
You can open file for editing, optionally at line n or at the first line matching pattern:
+[num] Start editing at line number num, or the last line of the file if num is omitted.
Eventually, I'd fix this in an easiest possible way:
func editFile(command, file string) error {
command += " " + file
return run(command, os.Stdin, os.Stdout)
}
Raised a PR for this: https://github.com/knqyf263/pet/pull/319
Best regards, Jarek
Indeed @jaroslawhartman , the +0 is added for editors like vi, vim, nano, etc. to jump to the end of the file where the new snippet is inserted and put the cursor in a place where the user can just start typing.
I think the most straightforward solution to this would be to add some conditionals there, depending on the editor that's being used.
Privileged issue
Issue Content
Related to
140
but it does not work on Powershell nor CMD/
(error in french, but basically command run is not windows compatible)
This is because the function to edit file is not Windows compatible https://github.com/knqyf263/pet/blob/f88549cbb1e7eb4853bf7929b659e083076bfc92/cmd/util.go#L17-L22
Configuring the editor can help if using one supportin
+<line>
work - like a Unix-like one(
vim
or equivalent can be made installed with Scoop)Then I can make it work with CMD (default).
It could be good to be able to support for Windows notepad or any other program like VSCOE (
Editor = "code"
).