Last active
August 29, 2015 13:57
-
-
Save np/9598621 to your computer and use it in GitHub Desktop.
ensure_link.sh
This file contains 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
# ensure_link() @ https://gist.github.com/np/9598621 {{{ | |
# Dependencies: | |
# error() @ https://gist.github.com/3736727 | |
ensure_link(){ | |
local src="$1" | |
local dst="$2" | |
if [ -L "$src" ]; then | |
# Check if the link is already as expected. | |
[ $(readlink "$src") != "$dst" ] || return 0 | |
rm "$src" | |
elif [ -d "$src" ]; then | |
rmdir "$src" | |
elif [ -e "$src" ]; then | |
error 1 "$src already exists, fix this and relaunch" | |
fi | |
ln -s "$dst" "$src" | |
} | |
# }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment