From f126c5cfcd68e28720cc5cd2d368734d89a5875e Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Mon, 8 Jul 2013 17:08:50 +0200 Subject: Support multiple source directories The `rcup` and `mkrc` commands now support multiple source directories. This is useful for sharing dotfiles between friends, spliting dotfiles into private and public ones, or other such situations. In `mkrc` this support means that you can specify the destination directory for your dotfile, either from the command-line or from you `~/.rcrc` configuration. In `rcup` this means that it will recur through all source directories, in order, creating the symlinks as needed. This means that duplicated files will not be overridden. The order can be specified by the `-d` option, which can be repeated, or by the `DOTFILES_DIRS` option in your `~/.rcrc` configuration. The `-d` option overrides the configuration. For example, this configuration file will update from the two directories in order: DOTFILES_DIRS="/home/mike/.dotfiles/public /home/mike/.dotfiles/private" Any source directories that don't exist are skipped. --- bin/rcup | 63 +++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 22 deletions(-) (limited to 'bin/rcup') diff --git a/bin/rcup b/bin/rcup index 0569997..64626b3 100755 --- a/bin/rcup +++ b/bin/rcup @@ -5,14 +5,12 @@ REPLACE_ALL=0 DEST_DIR=$HOME -DOTFILES_DIR=$HOME/.dotfiles +DEFAULT_DOTFILES_DIR=$HOME/.dotfiles HOSTNAME=`hostname -s` -HOST_FILES=$DOTFILES_DIR/host-$HOSTNAME DEBUG=: PRINT=echo VERBOSE=: PROMPT=echo -DIR_STACK=":$DOTFILES_DIR" MKDIR=mkdir LN=ln RM=rm @@ -138,11 +136,13 @@ handle_command_line() { arg_tags="" verbosity=0 version=0 - while getopts Vqvt: opt; do + dotfiles_dirs= + while getopts Vqvt:d: opt; do case "$opt" in t) arg_tags="$arg_tags $OPTARG";; v) verbosity=$(($verbosity + 1));; q) verbosity=$(($verbosity - 1));; + d) dotfiles_dirs="$dotfiles_dirs $OPTARG";; V) version=1 esac done @@ -173,6 +173,10 @@ handle_command_line() { TAGS=$arg_tags fi + if [ "x$dotfiles_dirs" != "x" ]; then + DOTFILES_DIRS=$dotfiles_dirs + fi + FILES=$@ } @@ -183,34 +187,49 @@ fi . `dirname $0`/../libexec/rcm/rcm.sh handle_command_line $* -cd $DOTFILES_DIR +if [ "x$DOTFILES_DIRS" = "x" ]; then + DOTFILES_DIRS="$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR" +fi + +for DOTFILES_DIR in $DOTFILES_DIRS; do -for file in ${FILES:-*}; do - host_portion=`echo $file | sed -e 's/host-.*/host-/'` - tag_portion=`echo $file | sed -e 's/tag-.*/tag-/'` - if ! metafile $file $host_portion $tag_portion; then - handle_file $file $DEST_DIR $DOTFILES_DIR 0 + if [ ! -d $DOTFILES_DIR ]; then + $VERBOSE "skipping non-existent directory: $DOTFILES_DIR" + continue fi -done -cd $DOTFILES_DIR + cd $DOTFILES_DIR + DIR_STACK=":$DOTFILES_DIR" -if [ -d $HOST_FILES ]; then - pushdir `basename $HOST_FILES` for file in ${FILES:-*}; do - handle_file $file $DEST_DIR $HOST_FILES 0 + host_portion=`echo $file | sed -e 's/host-.*/host-/'` + tag_portion=`echo $file | sed -e 's/tag-.*/tag-/'` + if ! metafile $file $host_portion $tag_portion; then + handle_file $file $DEST_DIR $DOTFILES_DIR 0 + fi done - popdir -fi -cd $DOTFILES_DIR + cd $DOTFILES_DIR -for tag in $TAGS; do - if [ -d tag-$tag ]; then - pushdir `basename tag-$tag` + host_files=$DOTFILES_DIR/host-$HOSTNAME + if [ -d $host_files ]; then + pushdir `basename $host_files` for file in ${FILES:-*}; do - handle_file $file $DEST_DIR $DOTFILES_DIR/tag-$tag 0 + handle_file $file $DEST_DIR $host_files 0 done popdir fi + + cd $DOTFILES_DIR + + for tag in $TAGS; do + if [ -d tag-$tag ]; then + pushdir `basename tag-$tag` + for file in ${FILES:-*}; do + handle_file $file $DEST_DIR $DOTFILES_DIR/tag-$tag 0 + done + popdir + fi + done + done -- cgit v1.2.3