Skip to content

Instantly share code, notes, and snippets.

@ajdiaz
Created November 3, 2010 10:38
Show Gist options
  • Save ajdiaz/660951 to your computer and use it in GitHub Desktop.
Save ajdiaz/660951 to your computer and use it in GitHub Desktop.
git post-commit hook to dot files.
#! /bin/bash
# (c) 2010 Andres J. Diaz <ajdiaz@connectical.com>
# Modified 2011 by Ryan Turner <rjturner@cmu.edu>
# 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
@ogarcia
Copy link

ogarcia commented Jun 23, 2011

Hi!

I have an idea. If you do this when you make the symbolic link:
ln -s "${dot##$HOME/}" "${home_dot}"
You can use a relative path when the repo is in user's home. It's more elegant than use the full path in symbolic links.

Grettengs!

@ajdiaz
Copy link
Author

ajdiaz commented Jul 20, 2011

Hi Oscar,

I commited the change that you proposed, now it's in public gist :)

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