Giter VIP home page Giter VIP logo

Comments (9)

itchyny avatar itchyny commented on August 24, 2024 1

Released as v0.1.6.

from mmv.

itchyny avatar itchyny commented on August 24, 2024

Hmm, this looks to work before merging #10, which allows command line flags in $EDITOR. Not sure how to fix both.

from mmv.

sk22 avatar sk22 commented on August 24, 2024

ahh, hm, i see... in this case, i guess C:\Progra~1\Micros~1\Code.exe --wait will work for me, even if it's not ideal (though very retro)

from mmv.

itchyny avatar itchyny commented on August 24, 2024

Using shell could help us? You can configure editor with space path and arguments like export EDITOR="'C:\Program Files\Microsoft VS Code\Code.exe' --wait" (note the single quotes). This looks like how editor config is handled in git (ref: https://git-scm.com/book/en/v2/Appendix-C%3A-Git-Commands-Setup-and-Config).

diff --git a/cmd/mmv/main.go b/cmd/mmv/main.go
index 8aed5bb..9a627fe 100644
--- a/cmd/mmv/main.go
+++ b/cmd/mmv/main.go
@@ -109,10 +109,8 @@ func rename(args []string) error {
 	if editor == "" {
 		editor = "vi"
 	}
-	editorWithArgs := strings.Fields(editor)
-	editorWithArgs = append(editorWithArgs, f.Name())
 
-	cmd := exec.Command(editorWithArgs[0], editorWithArgs[1:]...)
+	cmd := exec.Command("sh", "-c", editor+` "$@"`, "", f.Name())
 	cmd.Stdin = tty.Input()
 	cmd.Stdout = tty.Output()
 	cmd.Stderr = tty.Output()

from mmv.

itchyny avatar itchyny commented on August 24, 2024

Another patch to reduce the code by resolving the environment in the shell.

diff --git a/cmd/mmv/main.go b/cmd/mmv/main.go
index 8aed5bb..1a97724 100644
--- a/cmd/mmv/main.go
+++ b/cmd/mmv/main.go
@@ -105,14 +105,7 @@ func rename(args []string) error {
 	}
 	defer tty.Close()
 
-	editor := os.Getenv("EDITOR")
-	if editor == "" {
-		editor = "vi"
-	}
-	editorWithArgs := strings.Fields(editor)
-	editorWithArgs = append(editorWithArgs, f.Name())
-
-	cmd := exec.Command(editorWithArgs[0], editorWithArgs[1:]...)
+	cmd := exec.Command("sh", "-c", `eval exec ${EDITOR:-vi} '"$@"'`, "", f.Name())
 	cmd.Stdin = tty.Input()
 	cmd.Stdout = tty.Output()
 	cmd.Stderr = tty.Output()

from mmv.

itchyny avatar itchyny commented on August 24, 2024

Released as v0.1.5.

from mmv.

sk22 avatar sk22 commented on August 24, 2024

i suppose this works on linux, but it broke windows compatibility :/

C:\Users\user\Downloads\mmv_v0.1.5_windows_amd64>mmv *
mmv: abort renames: exec: "sh": executable file not found in %PATH%

sorry about not commenting earlier - i didn't find the time to try the new version until now

from mmv.

itchyny avatar itchyny commented on August 24, 2024

I fixed in the main branch. Make sure to confirm the issue is resolved in your environment.

from mmv.

sk22 avatar sk22 commented on August 24, 2024

that works, thanks!

from mmv.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.