-
-
Save jasonboukheir/3fdab92ece236744528447a4f7f5de00 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
if pwd | grep /mnt/c > /dev/null; then | |
exec git.exe "$@" | |
else | |
exec /usr/bin/git "$@" | |
fi |
It's really helpful in your bashrc file! Which is the file that loads all kinds of settings when bash is first initialized for any instance.
@roopjm thank you, I did, but it doesn't seem to work :(
Having this code in the Bash startup script is not going to be very useful, since you are only going to be able to use it if you are invoking git from within an interactive login shell. What you really want is to overload the git
executable that is found in the PATH
.
PATH
works exactly the same way on Linux as it does on Windows. It contains a list of directories that is searched for executables whenever you enter the name of a program in your terminal. The default path on Linux is something like /usr/local/bin:/usr/bin
. What you can see here is that /usr/local/bin
is searched before /usr/bin
, as such we can place stuff in there to overload other executables.
To know where your current git
is installed use command -v git
, which should give you /usr/bin/git
. Meaning, we can use /usr/local/bin
to overload it. So, let us do exactly that.
cat >/tmp/git <<'GIT'
#!/usr/bin/env bash
set -e
if [[ $(pwd -P) =~ ^/mnt/./ ]]
then exec /mnt/c/Program\ Files/Git/cmd/git.exe "$@"
else exec /usr/bin/git "$@"
fi
GIT
sudo install /tmp/git /usr/local/bin
That is all, no matter from where you invoke git it will be using your overloaded version going forward. Whenever you really want to us the original just use /usr/bin/git
.
You can do exactly the same with many other programs that read things from disk. For instance https://github.com/sharkdp/bat is really awesome, and available cross-platform. Just brew install bat
on Linux and choco install bat
on Windows and create an overload with exactly the same logic as in the git
overload (obviously replacing the paths to the executables), and enjoy a massive speed up.
Just use it as an alias. I use fish
, I added:
alias git "git.exe"
Hi! Can anyone help me - where exactly this code should go to? To which file? I'm totaly new to Linux/WSL2 and can't faind myself around it :(