mattn / memo

📓 Memo Life For You
MIT License
970 stars 79 forks source link

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

Open tsubasaxZZZ opened 4 years ago

tsubasaxZZZ commented 4 years ago

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 commented 4 years ago

Could you pleaes try this?

editor = "notepad ${FILES}"
tsubasaxZZZ commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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.