Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command to edit does not work on Windows unless configuring a Unix-like editor #314

Open
1 task done
cderv opened this issue Sep 12, 2024 · 3 comments
Open
1 task done

Comments

@cderv
Copy link

cderv commented Sep 12, 2024

Privileged issue

  • I've been directed through Discussions another issue to create an issue here.

Issue Content

Related to

but it does not work on Powershell nor CMD/

❯ pet configure
'+0' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
exit status 1

(error in french, but basically command run is not windows compatible)

This is because the function to edit file is not Windows compatible

pet/cmd/util.go

Lines 17 to 22 in f88549c

func editFile(command, file string, startingLine int) error {
// Note that this works for most unix editors (nano, vi, vim, etc)
// TODO: Remove for other kinds of editors - this is only for UX
command += " +" + strconv.Itoa(startingLine) + " " + file
return run(command, os.Stdin, os.Stdout)
}

Configuring the editor can help if using one supportin +<line> work - like a Unix-like one

[General]
  Editor = "vim"

(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").

@RamiAwar
Copy link
Collaborator

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

@jaroslawhartman
Copy link

jaroslawhartman commented Oct 7, 2024

I can confirm similar behaviour on MacOS - I have VSCode configured for edit and it's opening +0 file as well:
image

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: #319

Best regards,
Jarek

@RamiAwar
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants