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

How can I open files that is including space memodir? #50

Open
tsubasaxZZZ opened this issue Apr 14, 2020 · 4 comments
Open

How can I open files that is including space memodir? #50

tsubasaxZZZ opened this issue Apr 14, 2020 · 4 comments

Comments

@tsubasaxZZZ
Copy link

I set following config:

memodir = "C:/Users/tsunomur/OneDrive - Microsoft/memo"
editor = "notepad.exe"
column = 20
width = 0
selectcmd = "peco"
grepcmd = "grep -nH ${PATTERN} ${FILES}"
memotemplate = ""
assetsdir = "."
pluginsdir = "C:/Users/tsunomur/AppData/Roaming/memo/plugins"
templatedirfile = ""
templatebodyfile = ""

When I'm trying "memo edit", and after select a file, I got following error(Sorry for only Japanese):
image

Could you let me know how to write a configuration file to open a file under such a folder?
# I could open when remove call shellquote(file) but it's not correct solution...

@mattn
Copy link
Owner

mattn commented Apr 15, 2020

Could you pleaes try this?

editor = "notepad ${FILES}"

@tsubasaxZZZ
Copy link
Author

Sorry for my late reply. I tried but it failed.
I've found pattern of sucess.

correct work:

memodir = "C:\\temp"
editor = "notepad"

dosen't work:

memodir = "C:\\Users\\tsunomur\\OneDrive - Microsoft\\memo"
memodir = "C:\\Users\\tsunomur\\OneDrive\\ -\\ Microsoft\\memo"

I used procmon to see this behavior, and then it's try to access C:\"C:\Users\tsunomur\OneDrive - Microsoft\memo\2020-06-18-hoge.md\
image

@mattn
Copy link
Owner

mattn commented Jun 18, 2020

This memo command spawn executable editor with cmd /c .... So the path contains spaces should be handled to be quoted.

cmd /c notepad "C:\Users\tsunomur\OneDrive - Microsoft\memo"

This quotes does not work when using notepad. Could you please this patch?

diff --git a/main.go b/main.go
index a6e5dc8..1b07ba3 100644
--- a/main.go
+++ b/main.go
@@ -414,7 +414,9 @@ func (cfg *config) runfilter(command string, r io.Reader, w io.Writer) error {
 func (cfg *config) runcmd(command, pattern string, files ...string) error {
 	var args []string
 	for _, file := range files {
-		args = append(args, shellquote(file))
+		if strings.ContainsRune(file, ' ') {
+			args = append(args, shellquote(file))
+		}
 	}
 	cmdargs := strings.Join(args, " ")
 

@tsubasaxZZZ
Copy link
Author

I patched but same error occured..

diff --git a/main.go b/main.go
index a6e5dc8..0056410 100644
--- a/main.go
+++ b/main.go
@@ -414,9 +414,12 @@ func (cfg *config) runfilter(command string, r io.Reader, w io.Writer) error {
 func (cfg *config) runcmd(command, pattern string, files ...string) error {
        var args []string
        for _, file := range files {
-               args = append(args, shellquote(file))
+               if strings.ContainsRune(file, ' ') {
+                       args = append(args, shellquote(file))
+               }
        }
        cmdargs := strings.Join(args, " ")
+       fmt.Println(cmdargs)
$ go build
$ .\memo.exe new
Title: hoge
"C:\Users\tsunomur\OneDrive - Microsoft\memo\2020-06-18-hoge.md"
2020/06/18 16:16:40 notepad "C:\Users\tsunomur\OneDrive - Microsoft\memo\2020-06-18-hoge.md"

And when exec "config", it's openend blank notepad. It seem to need shellquote for other case.

Thank you for your cooperation. I'll investigate my situation continually and send PR.

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

2 participants