Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created August 23, 2021 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aiya000/7ddcef549f51ca5fe6c2aed91810375f to your computer and use it in GitHub Desktop.
Save aiya000/7ddcef549f51ca5fe6c2aed91810375f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Currently on NTFS, WSL2's git is too heavy.
sub_cmd=$1
function should_use_windows_git () {
[[ $(pwd) =~ '^/mnt/' ]] \
|| [[ $(pwd) =~ '/home/aiya000/Windows' ]] \
|| [[ $(pwd) =~ '/home/aiya000/Desktop' ]]
}
function is_needing_auth () {
local command_needs_auth=(push pull fetch) cmd
for cmd in "${command_needs_auth[@]}" ; do
if [[ $sub_cmd = "$cmd" ]] ; then
return 0
fi
done
return 1
}
if is_needing_auth ; then
# echo 'Using WSL2 git'
/usr/bin/git "$@"
return $?
fi
if [[ -z $ZSH_ENV_USE_WSL_GIT ]] && should_use_windows_git ; then
# echo 'Using git.exe'
git.exe "$@"
return $?
fi
# echo 'Using WSL2 git'
/usr/bin/git "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment