scphantm
scphantm

Reputation: 4533

using Notepad++ for git inside cygwin

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 "$*"

Upvotes: 9

Views: 5219

Answers (6)

peregine
peregine

Reputation: 3

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'

Upvotes: 0

eis
eis

Reputation: 53462

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})"

Upvotes: 0

Zombo
Zombo

Reputation: 1

#!/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

Upvotes: 0

Gene Pauly
Gene Pauly

Reputation: 1645

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.

Upvotes: 4

Aternus
Aternus

Reputation: 3475

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

Upvotes: 5

scphantm
scphantm

Reputation: 4533

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.

Upvotes: 17

Related Questions