Created
November 3, 2010 10:38
-
-
Save ajdiaz/660951 to your computer and use it in GitHub Desktop.
git post-commit hook to dot files.
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
#! /bin/bash | |
# (c) 2010 Andres J. Diaz <[email protected]> | |
# Modified 2011 by Ryan Turner <[email protected]> | |
# A hook to git-commit(1) to update the home dot files link using this | |
# repository as based. | |
# | |
# To enable this hook, rename this file to "post-commit". | |
for dot in $PWD/*; do | |
home_dot="$HOME/.${dot##*/}" | |
if [ -L "${home_dot}" ]; then | |
if [ "${home_dot}" -ef "$dot" ]; then | |
echo "[skip] ${home_dot##*/}: already updated" | |
else | |
rm -f "${home_dot}" && \ | |
ln -s "${dot##$HOME/}" "${home_dot}" && \ | |
echo "[done] ${home_dot##*/}: updated link" | |
fi | |
else | |
if [ -f "${home_dot}" ]; then | |
mv -f "${home_dot}" "${home_dot}.$(date +%s).bak" && \ | |
ln -s "${dot##$HOME/}" "${home_dot}" && \ | |
echo -n "[done] ${home_dot##*/}: regular file, " && \ | |
echo "moved to ${home_dot##*/}.$(date +%s).bak" | |
else | |
ln -s "${dot##$HOME/}" "${home_dot}" && \ | |
echo "[done] ${home_dot##*/}: created link" | |
fi | |
fi | |
done | |
true | |
# vim: sts=4:sw=4:tw=78:ft=sh:et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Oscar,
I commited the change that you proposed, now it's in public gist :)