9

This is an extension of this question

How do I use Notepad++ (or other) with msysgit?

i have done all combinations that i can think of for my shell script. when i have my cygwin console (im using mintty if it matters) i can type

npp {file}

and the file opens correctly. but when i do a

git rebase -i HEAD~5

npp opens with a blank new document, not the interactive file to control the rebase. any idea why this would be happening?

git --version
git version 1.7.9

latest version of cygwin on a windows 7 machine and NPP 5.9.8

also, here is my wrapper script

#!/bin/sh
"C:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar \
  -nosession -noPlugin "$*"
Community
  • 1
  • 1
scphantm
  • 4,293
  • 8
  • 43
  • 77
  • Cygwin, interesting. My script was to be used with msysgit, in a DOS or mwin bash session. For Cygwin, shouldn't be using cygwin paths? `/cygdrive/c/Program Files (x86)/...` – VonC Apr 18 '12 at 12:50
  • posix is turned on so windows paths inside cygwin work just fine, besides, i tried it both ways and neither worked. – scphantm Apr 18 '12 at 12:56
  • have you checked this http://superuser.com/q/168971/11855 – CharlesB Apr 18 '12 at 12:58
  • im working on an idea right now, im thinking that since this is a cygwin version of git, maybe the issue is git is passing it a cygwin path and npp doesn't know what to do with it. im looking at shell scripts that call cygpath to correct it. – scphantm Apr 18 '12 at 13:01

6 Answers6

17

I was correct about my cygwin path issue. i changed my shell wrapper to this

#!/bin/sh
'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar \
  -nosession -noPlugin "$(cygpath -w "$*")"

and it worked perfectly.

Zombo
  • 1
  • 62
  • 391
  • 407
scphantm
  • 4,293
  • 8
  • 43
  • 77
  • 1
    Excellent (+1). I have edited by original answer (http://stackoverflow.com/questions/1634161/how-do-i-use-notepad-or-other-with-msysgit/1635493#comment13111374_1635493) to include your conclusion (and reference back your answer). – VonC Apr 19 '12 at 06:16
  • 1
    I'm using cygwin and had some problems with the \ so I changed this to: #!/bin/sh 'C:/Apps/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin "$(cygpath -w "$*")" And now it works for me. Thanks a bunch for this. – jontejj Feb 11 '14 at 10:26
  • What do you mean by "shell wrapper" here? I'm having this issue with Sublime Text and can't figure it out. When I go to do a Git commit, it opens an empty file that doesn't exist. It looks for a path like this: "C:\c\Users\Jordan\Desktop\test\.git\COMMIT_EDITMSG" – Jordan Harris Jul 23 '15 at 01:32
  • Did you test your solution, when the filename/filepath being passed to your command line contains a space? – user1934428 Dec 28 '21 at 11:15
5

Here is the complete solution without a wrapper script.

These lines assume that you are using the 64bit version of Windows.

Run the following command from the command prompt (Cygwin):

git config --global core.editor \
  "'$(cygpath -u "C:\Program Files (x86)\Notepad++\notepad++.exe")' \
  -multiInst -notabbar -nosession -noPlugin"

This is an example of how your .gitconfig should look like after the command:

[core]
    excludesfile = /home/Aternus/.gitignore_global
    autocrlf = input
    safecrlf = true
    editor = '/cygdrive/c/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
Aternus
  • 3,375
  • 1
  • 14
  • 9
  • 3
    This could work just with Windows' version of Git, not Cygwin's, because Cygwin's Git would execute Notepad++ with Cygwin's path to the file: `notepad++.exe /home/user/repository/file.extension`. I'm sure Windows Notepad++ won't find such file. Even if you have you repo outside Cygwin's directories, it would look like this: `notepad++.exe /cygdrive/d/repository/file.extension`. – David Ferenczy Rogožan Aug 07 '14 at 15:50
  • 1
    When I use this, I get an empty notepad window opened when doing interactive rebase for example... – ddinchev Oct 08 '14 at 18:09
  • What's the point of fiddling with _cygpath -u_? You could have simply written `... core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' ...."`. Aside from this, I personally would find the use of a wrapper script easier to maintain and more flexible. – user1934428 Dec 28 '21 at 11:17
4

I've created a simple script for running arbitrary Windows commands with UNIX-style path arguments:

cygrun.sh

#!/bin/sh
if test -z "$1"; then
    echo "Usage: $(basename "$0" .sh) program [argument]..."
    exit 1
fi

program=$1
shift
if test $# -ge 0; then
    IFS=$'\n'
    exec "$program" $(cygpath -w "$@")
else
    exec "$program"
fi

Here's how I can use it in my git config (assuming cygrun is a symlink to cygrun.sh somewhere in PATH):

[core]
    editor = cygrun 'C:/Program Files/Notepad2/Notepad2.exe'
[difftool "diffmerge"]
    cmd = cygrun 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' \"$LOCAL\" \"$REMOTE\"

This way one script can fits many similar use cases, there's no need to create a separate wrapper every time. It can be convenient to use from command line as well.

Gene Pavlovsky
  • 1,515
  • 17
  • 14
  • 1
    An improved version of my script, which can also be used to run Cygwin tools using Windows paths: https://gist.github.com/gene-pavlovsky/e81c8e18327540f70df4e5296ff3dd15 Use `-w` option to run Windows tools with UNIX paths, and no options (or `-u`) to run Cygwin tools with Windows paths. – Gene Pavlovsky Apr 19 '16 at 21:59
0
#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}
  1. If no path, pass no path

  2. If path is empty, pass empty path

  3. If path is not empty, convert to Windows format.

Then I set these variables:

export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'
  1. EDITOR allows script to work with Git

  2. GIT_EDITOR allows script to work with Hub commands

Source

Zombo
  • 1
  • 62
  • 391
  • 407
0

There's an existing solution without a wrapper script that looks promising, but with cygwin git and cmd.exe, will just open an empty file every time.

To fix that, you'd need to have this in your .gitconfig (which with --global will reside in your cygwin home folder):

[core]
        editor = '/cygdrive/c/Program Files (x86)/Notepad++/notepad++.exe'  -multiInst -notabbar -nosession -noPlugin $(cygpath --windows "${1}")

Key thing being $(cygpath --windows "${1}") at the end.

Seems this will work on cmd.exe:

git config --global core.editor "'/cygdrive/c/Program Files (x86)/Notepad++/notepad++.exe'  -multiInst -notabbar -nosession -noPlugin $(cygpath --windows ${1})"
eis
  • 51,991
  • 13
  • 150
  • 199
0

I will suggest an alternative simple answer to dealing with the argument file paths to notepad using cygpath.

Create a symbolic link in windows to your home directory under cgywin. In this way notepad will be able to find the input files through the symbolic link.

On my PC, I opened cmd with "Run as administrator" and type in the following under C:\ :

    C:\>mklink /D home cygwin64\home

With this, you can simply configure git as follows (taken from previous answers) and assuming notepad is installed at the following directory:

    git config --global core.editor '/cygdrive/c/Program Files (x86)/Notepad++/notepad++.exe'
peregine
  • 3
  • 3