Skip to content

Instantly share code, notes, and snippets.

@emson

emson/dotfile.sh

Created Mar 2, 2012
Embed
What would you like to do?
dotfile.sh allows you to sync all your '.files' using Dropbox
#!/bin/sh
REPO=$HOME/Dropbox/Dotfiles
PLATFORM=$(uname)
die() {
echo "fatal: $1"
exit 1
}
dotfile_add() {
source="$1"
base=${source#.}
dest="$REPO/$base"
test -e "$source" || die "no such dotfile"
test -e "$dest" && die "target dotfile already exists"
mv -v "$source" "$dest" || die "move failed"
ln -s "$dest" "$source" || die "link failed"
}
dotfile_linkall() {
for dotfile in $REPO/* ; do
base=$(basename "$dotfile")
case $base in
(*-$PLATFORM)
dest="$HOME/.${base%-$PLATFORM}"
;;
(*-Darwin|*-Linux)
dest=nil
;;
(*)
dest="$HOME/.$base"
;;
esac
test "$dest" != nil || continue
ln -sf "$dotfile" "$dest"
done
}
case $1 in
add|linkall)
dotfile_$1 "$2"
;;
*) die "bad option '$1'."
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment