#!/bin/sh # set -x DOTFILES=$HOME/.dotfiles MV=mv INSTALL=rcup ROOT_DIR=$HOME destination() { if [ $# -eq 0 ]; then echo $DOTFILES else echo $DOTFILES/tag-$2 fi } install_dotfile() { prior_wd=`pwd` cd $DOTFILES $INSTALL -t ${2:--} $1 cd $prior_wd } . `dirname $0`/../libexec/rcm/rcm.sh if [ $# -eq 0 ]; then echo "Usage: dotfiles-add [-t tag] filename ..." exit 1 fi tag= verbosity=0 version=0 while getopts Vvqt: opt; do case "$opt" in t) tag=$OPTARG;; v) verbosity=$(($verbosity + 1));; q) verbosity=$(($verbosity - 1));; V) version=1 esac done shift $(($OPTIND-1)) if [ $version -eq 1 ]; then version mkrc exit 0 elif [ $verbosity -ge 2 ]; then MV="$MV -v" INSTALL="$INSTALL -vv" elif [ $verbosity -eq 1 ]; then MV="$MV -v" INSTALL="$INSTALL -v" elif [ $verbosity -eq 0 ]; then MV="$MV -v" else INSTALL="$INSTALL -q" fi files=$@ for file in $files; do dotless=`echo $file | sed -e "s|$ROOT_DIR/||" | sed -e 's/^\.//'` dest=`destination $dotless $tag` mkdir -p $dest/`dirname $dotless` $MV $file $dest/$dotless install_dotfile $dotless $tag done