Skip to content

Instantly share code, notes, and snippets.

@nrh
Created January 25, 2012 00:33
Show Gist options
  • Save nrh/1673791 to your computer and use it in GitHub Desktop.
Save nrh/1673791 to your computer and use it in GitHub Desktop.
#!/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