threads / discuss / 29196

Escape character for .gitconfig

Subject: Escape character for .gitconfig

## tl;dr

9 messages between Dec 17, 2011 and Dec 21, 2011.

replies: 8people: 5as markdown or json

Erik Blake· Dec 17, 2011, 10:10 UTC · lore

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?

Jeff King· Dec 17, 2011, 10:58 UTC · re: Erik Blake · lore

Re: Escape character for .gitconfig

On Sat, Dec 17, 2011 at 11:10:37AM +0100, Erik Blake wrote:
Show 14 quoted lines
> 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

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
Erik Blake· Dec 18, 2011, 07:53 UTC · re: Jeff King · lore

Re: Escape character for .gitconfig

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
 >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.
On 2011-12-17 11:58, Jeff King wrote:
Show 28 quoted lines
> On Sat, Dec 17, 2011 at 11:10:37AM +0100, Erik Blake wrote:
>
>> 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
>
> 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
Jeff King· Dec 18, 2011, 09:51 UTC · re: Erik Blake · lore

Re: Escape character for .gitconfig

On Sun, Dec 18, 2011 at 08:53:09AM +0100, Erik Blake wrote:
> 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. :)

> 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
> >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
Dirk Süsserott· Dec 19, 2011, 15:59 UTC · re: Jeff King · lore

Re: Escape character for .gitconfig

Am 18.12.2011 10:51 schrieb Jeff King:
> On Sun, Dec 18, 2011 at 08:53:09AM +0100, Erik Blake wrote:
> 
[...]
>> 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
>>> git commit --amend
[...]
Show 6 quoted 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
Erik Blake· Dec 20, 2011, 08:04 UTC · re: Dirk Süsserott · lore

Re: Escape character for .gitconfig

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

On 2011-12-19 16:59, Dirk Süsserott wrote:
Show 22 quoted lines
> Am 18.12.2011 10:51 schrieb Jeff King:
>> On Sun, Dec 18, 2011 at 08:53:09AM +0100, Erik Blake wrote:
>>
> [...]
>>> 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
>>>> git commit --amend
> [...]
>> 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
Dirk Süsserott· Dec 20, 2011, 19:46 UTC · re: Erik Blake · lore

Re: Escape character for .gitconfig

Am 20.12.2011 09:04 schrieb Erik Blake:
Show 12 quoted 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).
>
> 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
Peter Krefting· Dec 21, 2011, 12:54 UTC · re: Erik Blake · lore

Re: Escape character for .gitconfig

Erik Blake:
> 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).

-- 
\\// Peter - http://www.softwolves.pp.se/
demerphq· Dec 21, 2011, 13:59 UTC · re: Peter Krefting · lore

Re: Escape character for .gitconfig

On 21 December 2011 13:54, Peter Krefting <peter@softwolves.pp.se> wrote:
Show 11 quoted lines
> Erik Blake:
>
>
>> 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
-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

← back to recent threads