Created
February 22, 2018 09:35
-
-
Save gpakosz/1cd351da86ed1ccc165992aba0c54a38 to your computer and use it in GitHub Desktop.
A shell ln() function that defers to mklink on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case $(uname -s) in | |
*MINGW*) | |
ln() { | |
options="$1" | |
target="$2" | |
link="$3" | |
if ! [ -L "$link" ] && [ -d "$link" ]; then | |
link="$link/$(basename "$target")" | |
fi | |
case "$options" in | |
*f*) | |
rm -rf "$link" | |
esac | |
directory="" | |
if [ -d "$(dirname "$link")/$target" ]; then | |
directory="/D" | |
fi | |
cmd.exe /C "mklink "$directory" $(echo "$link" | sed 's/\//\\/g') $(echo "$target" | sed 's/\//\\/g') >NUL 2>&1" | |
} | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this from Git for Windows'
bash
because our Android builds (supported on Linux and Mac) make use of symlinks before callingndk-build
.Tested with symlinks only.