Skip to contentSkip to conversation

Escape character for .gitconfig

DISCUSSION Erik Blake 5 participants 9 messages Jun 15, 2016

lore
Share & tools
lore

Erik Blake

author
#0 lore raw

I have an editor path that includes "(" and ")". No matter how I try to escape this character, I get either variations on:

C:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: syntax error near unexpected token (' C:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: C:/Program Files (x86)/Notepad++/notepad++.exe \$@\'
error: There was a problem with the editor 'C:/Program Files (x86)/Notepad++/notepad++.exe'. Please supply the message using either -m or -F option.

or:

fatal: bad config file line 5 in C:\Users\xxx/.gitconfig

As you can see, I'm running git on a Win7 64 machine. Is there any way to escape the brackets? Or do I need to reinstall notepad++ on a different path?

#1 lore raw
Quoted 11 lines · Erik Blake

I have an editor path that includes "(" and ")". No matter how I try to escape this character, I get either variations on:

C:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: syntax error near unexpected token `('
C:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0:
`C:/Program Files (x86)/Notepad++/notepad++.exe \$@\'
error: There was a problem with the editor 'C:/Program Files (x86)/Notepad++/notepad++.exe'.
Please supply the message using either -m or -F option.

Quoted 3 lines

or:

fatal: bad config file line 5 in C:\Users\xxx/.gitconfig

You didn't tell us what you actually tried, so I don't know where you went wrong.

But you will need to quote the whole value for git to read from your gitconfig, and then quote any metacharacters in the value so that the shell doesn't interpret them. I think you want:

[core]

    editor = "'C:/Program Files (x86)/Notepad++/notepad++.exe'"

-Peff

author
#2 lore raw

Thanks Jeff,
That did the trick for this git newb. For the record, I had tried \(, /(, double- and single-quoting the entire path (note that git config --global had removed the quotes that were originally around the string). Did not think of "nested" quotes.

Now, however, I have a different problem in that notepad++ is somehow signalling git that editing is complete before I even get a chance to edit the file. I am trying the command

Quoted 1 line

git commit --amend

Notepad++ opens with the message, but git completes the commit before I get a chance to make any changes. I suspect the issue is that git fires up a new instance of notepad++ (which in my case is already running with some other files open). notepad++ sees the new instance starting and subsumes it under the pre-existing instance and then closes the new instance. git sees the task close and assumes I am done editing.

Oh well. Cannot use notepad.exe because it does not handle <lf> line endings. I guess I'll stick to the git gui.

e.

Quoted 28 lines · Jeff King
Quoted 11 lines · Erik Blake

I have an editor path that includes "(" and ")". No matter how I try to escape this character, I get either variations on:

C:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: syntax error near unexpected token `('
C:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0:
`C:/Program Files (x86)/Notepad++/notepad++.exe \$@\'
error: There was a problem with the editor 'C:/Program Files (x86)/Notepad++/notepad++.exe'.
Please supply the message using either -m or -F option.

Quoted 3 lines

or:

fatal: bad config file line 5 in C:\Users\xxx/.gitconfig

You didn't tell us what you actually tried, so I don't know where you went wrong.

But you will need to quote the whole value for git to read from your gitconfig, and then quote any metacharacters in the value so that the shell doesn't interpret them. I think you want:

   [core]
     editor = "'C:/Program Files (x86)/Notepad++/notepad++.exe'"

-Peff

#3 lore raw
Quoted 4 lines · Erik Blake

That did the trick for this git newb. For the record, I had tried \(, /(, double- and single-quoting the entire path (note that git config --global had removed the quotes that were originally around the string). Did not think of "nested" quotes.

Yeah, if you are using "git config" to enter it on the command line, you'll have to put an extra layer of quoting around it to pass it through the shell you're currently running. That's why I showed the example as the actual config file text. :)

Quoted 4 lines

Now, however, I have a different problem in that notepad++ is somehow signalling git that editing is complete before I even get a chance to edit the file. I am trying the command

Quoted 1 line

git commit --amend

Yep. This is a general problem with editors that open files in an existing session. The only signal git has of the user being done editing is when when the editor process exits. For many editors, there is an option or other trick for sticking around until the file is closed.

I know nothing about notepad++, but a quick google turned up the "-multiInst" option, which would avoid attaching to the existing instance. That might work for you.

-Peff

#4 lore raw

Am 18.12.2011 10:51 schrieb Jeff King:

Quoted 2 lines · Erik Blake

[...]

Quoted 4 lines
Quoted 4 lines

Now, however, I have a different problem in that notepad++ is somehow signalling git that editing is complete before I even get a chance to edit the file. I am trying the command

Quoted 1 line

git commit --amend

[...]

Quoted 6 lines

I know nothing about notepad++, but a quick google turned up the "-multiInst" option, which would avoid attaching to the existing instance. That might work for you.

-Peff

Jeff is right! I also use notepad++ and have set

export GIT_EDITOR='notepad++ -multiInst'

in my .bashrc (msysGit). And btw: notepad++ DOES handle cr/lf. Look at the "Format" menu.

Dirk

author
#5 lore raw

Hi Dirk,

I ended up using "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" which works nicely for me (note the placement of the inner quotations).

It is notepad.exe (the default Windows editor) that fails on files with only <lf> termination. That's why I was trying to set notepad++ as the git editor as it is vastly superior.

Cheers,
Erik

Quoted 22 lines · Dirk Süsserott

Am 18.12.2011 10:51 schrieb Jeff King:

Quoted 2 lines · Erik Blake

[...]

Quoted 4 lines
Quoted 4 lines

Now, however, I have a different problem in that notepad++ is somehow signalling git that editing is complete before I even get a chance to edit the file. I am trying the command

Quoted 1 line

git commit --amend

[...]

Quoted 5 lines

I know nothing about notepad++, but a quick google turned up the "-multiInst" option, which would avoid attaching to the existing instance. That might work for you.

-Peff

Jeff is right! I also use notepad++ and have set

export GIT_EDITOR='notepad++ -multiInst'

in my .bashrc (msysGit). And btw: notepad++ DOES handle cr/lf. Look at the "Format" menu.

Dirk

#6 lore raw

Am 20.12.2011 09:04 schrieb Erik Blake:

Quoted 6 lines

Hi Dirk,

I ended up using "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" which works nicely for me (note the placement of the inner quotations).

Quoted 6 lines

It is notepad.exe (the default Windows editor) that fails on files with only <lf> termination. That's why I was trying to set notepad++ as the git editor as it is vastly superior.

Cheers,
Erik

Hi Erik,

oops, I overread that you talked about notepad (not notepad++) and the <lf> stuff. My fault. I use the portable version of notepad++ and don't have the "space in path" problem. But if you mainly use the git-bash (as I do) instead of cmd.exe, then probably you could tweak your .bashrc:

export PATH="/C:/Program Files (x86)/Notepad++":$PATH

and then run notepad++ w/o giving the absolute path.

Cheers,
Dirk

#7 lore raw
In reply to Erik Blake

Erik Blake:

Quoted 1 line

As you can see, I'm running git on a Win7 64 machine. Is there any way to escape the brackets? Or do I need to reinstall notepad++ on a different path?

Just use the 8.3 path instead, using either "C:/Progra~1" or "C:/Progra~2" (depending on how the system got installed). You can mix 8.3 and long paths in the same command (so keeping the "Notepad++" component is fine).

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#8 lore raw
Quoted 11 lines · Peter Krefting

Erik Blake:

Quoted 3 lines

As you can see, I'm running git on a Win7 64 machine. Is there any way to escape the brackets? Or do I need to reinstall notepad++ on a different path?

Just use the 8.3 path instead, using either "C:/Progra~1" or "C:/Progra~2" (depending on how the system got installed). You can mix 8.3 and long paths in the same command (so keeping the "Notepad++" component is fine).

Or use a junction to make an alias of the name without strange chars....

Yves

Signature · 1 line
perl -Mre=debug -e "/just|another|perl|hacker/"