Created
January 25, 2012 00:33
-
-
Save nrh/1673791 to your computer and use it in GitHub Desktop.
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 -x | |
# describe symlink destination as ["#]file: .foo, assume $HOME | |
for file in dot.*; do | |
dest=`grep '^[\"\#\/].*.file:' "$file"|gawk -F'[:[:space:]]' '{print \$3}'` | |
dest=$(eval echo $dest) | |
destdir=${dest%/*} | |
if [ "$destdir" != "$dest" -a ! -d "${HOME}/${destdir}" ]; then | |
#echo "mkdir $HOME/$destdir" | |
mkdir -p "${HOME}/${destdir}" | |
fi | |
lwd=${PWD#$HOME/} | |
if [ -r "${HOME}/${dest}" -o -L "${HOME}/${dest}" ]; then | |
if ! cmp -s "$file" "${HOME}/${dest}"; then | |
mv "${HOME}/${dest}" "${HOME}/${dest}.orig" | |
else | |
rm "${HOME}/${dest}" | |
fi | |
fi | |
linktarget=${dest//[^\/]/} | |
linktarget=${linktarget//\//..\/} | |
echo "${HOME}/${dest} -> ${linktarget}${lwd}/$file" | |
ln -s "${linktarget}${lwd}/$file" "${HOME}/${dest}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment