aboutsummaryrefslogtreecommitdiff
path: root/metadot
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-02-01 01:25:10 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-02-01 01:25:10 -0200
commit6b9187673ee62d11042832f938913f15131592a7 (patch)
tree9e70016667efe273a72ab351aafaddbdb099e123 /metadot
parent25235935e6c90557a4d6791c8d8f3a5cdf89681a (diff)
downloaddotfiles-6b9187673ee62d11042832f938913f15131592a7.tar.gz
dotfiles-6b9187673ee62d11042832f938913f15131592a7.tar.bz2
Adding metadot script
Diffstat (limited to 'metadot')
-rwxr-xr-xmetadot86
1 files changed, 86 insertions, 0 deletions
diff --git a/metadot b/metadot
new file mode 100755
index 0000000..900e15f
--- /dev/null
+++ b/metadot
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# metadot: a dotfile manager
+#
+
+# Parameters
+OPT="$1"
+DATE="`date +%Y%m%d%I%M%S`"
+BASENAME="`basename $0`"
+DOT="$HOME/.dotfiles"
+MODULES="$DOT/modules"
+BACKUPS="$HOME/.backups/$DATE"
+
+# Backup a file
+function metadot_backup {
+ local file="$HOME/$1"
+
+ if [ -e "$file" ] || [ -h "$file" ]; then
+ local folder="$BACKUPS/`dirname $1`"
+
+ #echo "Backing up `basename $1`..."
+ mkdir -p $folder
+ mv $file $folder
+ fi
+}
+
+# Find contents of a module
+function metadot_find {
+ local module="$1"
+ ( cd $MODULES/$module && find -name '*.link' -or -name '*.dot.link' ) | sed -e 's|./||'
+}
+
+# Load a module
+function metadot_load {
+ local module="$1"
+ local destname
+ local dirname
+
+ if [ -d "$MODULES/$module" ]; then
+
+ echo "Loading module $module..."
+
+ for file in `metadot_find $module`; do
+ echo "Processing $file..."
+
+ # Get the dirname, replacing string.dot with .string
+ dirname="`echo $file | sed -e 's|\([^/]*\).dot/|.\1/|g'`"
+ dirname="`dirname $dirname`"
+
+ if echo $file | grep -q '.dot.link'; then
+ destname=".`basename $file .dot.link`"
+ else
+ destname="`basename $file .link`"
+ fi
+
+ if [ "$dirname" != "." ]; then
+ #echo "Creating $HOME/$dirname..."
+ mkdir -p $HOME/$dirname
+ else
+ dirname=""
+ fi
+
+ metadot_backup "$dirname/$destname"
+
+ #echo "Installing symlink $dirname/$destname..."
+ ln -s $MODULES/$module/$file $HOME/$dirname/$destname
+
+ done
+
+ echo "Backups saved at $BACKUPS."
+
+ else
+ echo "No such module $module"
+ fi
+}
+
+# Parsing.
+if [ -z "$OPT" ]; then
+ echo "usage: $BASENAME <option> [arguments]"
+ exit 1
+elif [ "$OPT" == "update" ]; then
+ ( cd $DOT && git pull origin master && git submodule update --init )
+elif [ "$OPT" == "load" ]; then
+ shift
+ metadot_load $*
+fi