Changing directory in Git-Bash: using Windows-style directory addresses in MINGW64 on Windows machines

Viewed 3510

Question:

git-bash.exe, or MINGW64, recognizes cd commands for directories whose addresses are given in form of: /Drive_Name/Folder1/Subfolder1. An example for changing to home dir for a Windows machine users is: cd /c/users/USERNAME.

  • Is it possible to use the following syntax? cd c:\users\USERNAME Note, the directory address is given in its "native" format: the syntax for which the Windows OS recognizes.

  • Alternatively, is there a way to automatically change all the backward slashes into forward slashes when pasting into the Git-bash window?

Background

I am using git-bash.exe on a daily basis: to pull and push to Github, to run latexmk for compiling my *.tex documents and to SSH my Linux machines. It would be nice to quickly start a git-bash.exe process at the desired directory location. And, when on Windows OS, getting addresses in form of C:\users\USERNAME\project is the default.

Assortment of syntax that git-bash.exe likes:

  • Format 1: the format native to GNU --- /c/users/USERNAME;
  • Format 2: semi-Windows OS format ==> use forward slash as divider --- c:/users/USERNAME;
  • Format 3: semi-Windows OS format ==> use TWO backward slashes as divider --- c:\\users\\USERNAME (credits: @VonC)

Alternatively (pending solutions)

A valid alternative is to have some third-party process to monitor the clipboard, and switch all the backward backward slashes into forward slashes. In my case, this could happen:

  1. [Solved] In Vim, when I use the following mapping to fetch the "parent directory" of the file: nnoremap <leader><leader>p :let @* = expand("%:p:h")<CR>

    • Solution: set shellslash, see "tentative solution" for more details.
  2. Though some clipboard-monitor/recording apps: to simply recognize that the string being assigned to the system clipboard is an address for a folder/directory, and replace all backward slashes to be forward slashes.

3 Answers
Related