1

I installed the Ubuntu WSL on my Windows 11. To learn Linux and Use Git, of all things. I was given Instructions to change my .bash_profile located on Linux Home directory (~) and create an alias like this:

alias npp='/mnt/c/"Program Files"/Notepad++/notepad++.exe'

Just to let the Linux console know where notepad is located and just use the command npp instead of the full notepad++.exe

Then I was told to add this configuration to my .gitconfig file, also located in my linux home directory (~)

[core]
editor = '/mnt/c/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPuglin

When I use the alias npp with an explicit path or I go into the Directory, everything works fine:

npp /home/dmolina/projects/starter-web/simple.txt

npp simple.txt (In the directory the file is located)

enter image description here

I can also use special keys like ~, and the console is smart enough to send Notepad++, something it Understands. But if I were to pass npp a a path where any of it's directories has spaces in the name then it will pass notepad ++ the linux path beginning with a C:\

For example:

npp /mnt/c/Users/NameMolina/OneDrive - something.com/Desktop/debug.txt

npp /mnt/c/Users/NameMolina/'OneDrive - something.com'/Desktop/debug.txt

npp /mnt/c/Users/NameMolina/"OneDrive - something.com"/Desktop/debug.txt

Notepad will throw this message

enter image description here

"C:\mnt\c\Users\NameMolina'OneDrive - someting.com'\Desktop\debug.txt" can not be opened : Folder doesn't exists.

The same thing happens if I make a commit for a Git Repository that is outside the linux filesystem.

enter image description here

I know that I can always put the project files and repositories inside the Linux file directory, but I searched online, and there seem to be scripts, and other ways that I can take the path sent by git and convert it to something notepad++ can understand. Those things are foreign to me and pointed to a solution using the cywing bash and the cwyngpath command a similar command to wslpath.

using Notepad++ for git inside cygwin How to translate the wslpath /home/user/ to windows path

I would like to see any help on this for the moment I was able to place something like this on my .gitconfig file

[core]
editor = '/mnt/c/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPuglin  $(wslpath -w "${1}")

and by joining the error messages notepadd++ launches I has able to get the whole Usage Page

wslpath: unrecognized option: h
wslpath: Invalid argument
Usage:
    -a    force result to absolute path format
    -u    translate from a Windows path to a WSL path (default)
    -w    translate from a WSL path to a Windows path
    -m    translate from a WSL path to a Windows path, with '/' instead of '\'

It seems to be a simple fix for people that understand what a wrapper is and how it works, the other posts are quite old, and I know my issue is my curiosity looking really hard at my cat, but I can almost feel the solution coming through, I was hoping someone could take a look at it and have the revelation I'm missing. Hoping also that this helps someone else in the future , wanting to integrate the Linux WSL in their Git Workflow and is not a waste of someone else's time.

starball
  • 20,030
  • 7
  • 43
  • 238
malta59
  • 97
  • 1
  • 9

1 Answers1

2

Create giteditor script and make it executable

#!/bin/bash 

arg=$(wslpath -aw "$1")
/mnt/c/"Program Files"/Notepad++/notepad++.exe -multiInst -notabbar -nosession -noPlugin "${arg}"

Add your script to ~/.gitconfig

[core]
        editor = /path/to/giteditor

enter image description here

ufopilot
  • 3,269
  • 2
  • 10
  • 12