windowsgitportable-applications

How can I set the portable text editor as default text editor of Git portable?


Windows, Git v2.11 portable

On the current computer my USB-flash drive has E: name. But on other computer it can to have other letter (for example F: or G:)...

My portable Git (v2.11) is located on the <My USB-drive>:\apps\PortableGit-2.11\ folder. My portable text editor (Sublime Text 3) is located on the <My USB-drive>:\apps\Sublime-Text-3\ folder.

If I write the core.editor value with E then it works fine on my current computer (when I launch the git commit command):

git config --system core.editor "'E:/apps/Sublime-Text-3/sublime_text.exe' -n -w"

But it will not work on other computers where my USB-drive's name uses other letter.

How can I set the portable text editor as default text editor of Git portable without that problem? Is it possible to point the path relatively of portable Git location?


Solution

  • There are 2 enviroment variables that you can use: HOMEDRIVE and EXEPATH.

    HOMEDRIVE - the drive that you ran from (eg: C:)

    EXEPATH - the full path of where the git ran from (eg: "C:\\MyApps\\GitPortable")

    So you can use those 2 in your gitconfig:

    editor = "$HOMEDRIVE/apps/Sublime-Text-3/sublime_text.exe"

    You need to make sure that the $HOMEDRIVE appears in the gitconfig file (and not manipulated by the shell, so run git config --system --edit and add it directly to there (under [core] section). Also make sure the variables are not inside single quotes ''