Skip to content

Instantly share code, notes, and snippets.

@gpakosz
Created February 22, 2018 09:35
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 gpakosz/1cd351da86ed1ccc165992aba0c54a38 to your computer and use it in GitHub Desktop.
Save gpakosz/1cd351da86ed1ccc165992aba0c54a38 to your computer and use it in GitHub Desktop.
A shell ln() function that defers to mklink on Windows
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
@gpakosz
Copy link
Author

gpakosz commented Feb 22, 2018

I used this from Git for Windows' bash because our Android builds (supported on Linux and Mac) make use of symlinks before calling ndk-build.

Tested with symlinks only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment