diff options
author | Mike Burns <mike@mike-burns.com> | 2013-06-07 10:49:17 +0200 |
---|---|---|
committer | Mike Burns <mike@mike-burns.com> | 2013-06-07 10:49:17 +0200 |
commit | 3c6cbc343d19e221756be024ba8d5bf2632c38d7 (patch) | |
tree | 0283693945dd131924d6e0b005ca588ff201d9f1 /bin/mkrc |
Initial commit
This adds mkrc and rcup, along with a Makefile to handle installation.
`rcup` is for installing files from the `~/.dotfiles` repo. It allows
for tagged files and host-specific files, and can install/update one-off
files.
`mkrc` is for moving a normal file into the dotfiles repo.
Diffstat (limited to 'bin/mkrc')
-rwxr-xr-x | bin/mkrc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/mkrc b/bin/mkrc new file mode 100755 index 0000000..39714ec --- /dev/null +++ b/bin/mkrc @@ -0,0 +1,60 @@ +#!/bin/sh + +set -x + +DOTFILES=$HOME/.dotfiles +MV=mv +INSTALL=./install +ROOT_DIR=$HOME + + +destination() { + if [ $# -eq 1 ]; then + echo $DOTFILES/$1 + else + echo $DOTFILES/tag-$2/$1 + fi +} + +install_dotfile() { + prior_wd=`pwd` + cd $DOTFILES + $INSTALL -t ${2:--} $1 + cd $prior_wd +} + +if [ $# -eq 0 ]; then + echo "Usage: dotfiles-add [-t tag] filename ..." + exit 1 +fi + +tag= +verbosity=0 +while getopts vqt: opt; do + case "$opt" in + t) tag=$OPTARG;; + v) verbosity=$(($verbosity + 1));; + q) verbosity=$(($verbosity - 1));; + esac +done +shift $(($OPTIND-1)) + +if [ $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/^\.//'` + $MV $file `destination $dotless $tag` + install_dotfile $dotless $tag +done |