summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Mike Burns <mike@mike-burns.com>2013-07-08 17:08:50 +0200
committerGravatar Mike Burns <mike@mike-burns.com>2013-07-09 21:24:19 +0200
commitf126c5cfcd68e28720cc5cd2d368734d89a5875e (patch)
tree52a11f057023ef8204e0e83752a07303325e3634
parent2e2573fbe07d8a1750ccdda7e0a146fef55fd50d (diff)
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.
-rw-r--r--README.md5
-rwxr-xr-xbin/mkrc30
-rwxr-xr-xbin/rcup63
-rw-r--r--man/man1/mkrc.110
-rw-r--r--man/man1/rcup.110
-rw-r--r--man/man5/rcrc.56
6 files changed, 85 insertions, 39 deletions
diff --git a/README.md b/README.md
index 40acc40..5d5e61b 100644
--- a/README.md
+++ b/README.md
@@ -23,9 +23,10 @@ Programs
--------
* `rcup` is the main program. It is used to install and update dotfiles,
- with support for tags and host-specific files.
+ with support for tags, host-specific files, and multiple source
+ directories.
* `mkrc` is for introducing a dotfile into your dotfiles directory, with
- support for tags.
+ support for tags and multiple source directories.
Support
-------
diff --git a/bin/mkrc b/bin/mkrc
index cf360bf..8b262be 100755
--- a/bin/mkrc
+++ b/bin/mkrc
@@ -2,42 +2,52 @@
# set -x
-DOTFILES=$HOME/.dotfiles
+DEFAULT_DOTFILES_DIR=$HOME/.dotfiles
MV=mv
INSTALL=rcup
ROOT_DIR=$HOME
destination() {
- if [ $# -eq 0 ]; then
- echo $DOTFILES
+ if [ $# -eq 2 ]; then
+ echo $1
else
- echo $DOTFILES/tag-$2
+ echo $1/tag-$3
fi
}
install_dotfile() {
prior_wd=`pwd`
- cd $DOTFILES
- $INSTALL -t ${2:--} $1
+ cd $1
+ $INSTALL -t ${3:--} $2
cd $prior_wd
}
+if [ -e $HOME/.rcrc ]; then
+ . $HOME/.rcrc
+fi
+
. `dirname $0`/../libexec/rcm/rcm.sh
if [ $# -eq 0 ]; then
- echo "Usage: dotfiles-add [-t tag] filename ..."
+ echo "Usage: dotfiles-add [-d dir] [-t tag] [-v] [-q] filename ..."
exit 1
fi
+for DOTFILES_DIR in $DOTFILES_DIRS $DEFAULT_DOTFILES_DIR; do
+ break
+done
+
tag=
verbosity=0
version=0
-while getopts Vvqt: opt; do
+
+while getopts Vvqt:d: opt; do
case "$opt" in
t) tag=$OPTARG;;
v) verbosity=$(($verbosity + 1));;
q) verbosity=$(($verbosity - 1));;
+ d) DOTFILES_DIR=$OPTARG;;
V) version=1
esac
done
@@ -62,8 +72,8 @@ files=$@
for file in $files; do
dotless=`echo $file | sed -e "s|$ROOT_DIR/||" | sed -e 's/^\.//'`
- dest=`destination $dotless $tag`
+ dest=`destination $DOTFILES_DIR $dotless $tag`
mkdir -p $dest/`dirname $dotless`
$MV $file $dest/$dotless
- install_dotfile $dotless $tag
+ install_dotfile $DOTFILES_DIR $dotless $tag
done
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
diff --git a/man/man1/mkrc.1 b/man/man1/mkrc.1
index 37a25b9..b241e6b 100644
--- a/man/man1/mkrc.1
+++ b/man/man1/mkrc.1
@@ -4,12 +4,13 @@
mkrc \- bless files into a dotfile
.SH SYNOPSIS
-.B mkrc [-v] [-q] [-t \fItag\fR] \fIfiles...\fR
+.B mkrc [-v] [-q] [-t \fItag\fR] [-d \fIdir\fR] \fIfiles...\fR
.SH DESCRIPTION
This program adds files to your dotfiles directory then installs it
-back into your home directory. It can install files under a tag.
+back into your home directory. It can install files under a tag or
+different source directory.
It supports these options:
@@ -25,6 +26,11 @@ decrease verbosity
\fB-t\fR \fITAG\fR
install dotfiles according to tag
+.TP
+\fB-d\fR \fIDIR\fR
+install dotfiles under the specified directory. This can be specified
+multiple times.
+
.SH AUTHOR
Written by Mike Burns.
diff --git a/man/man1/rcup.1 b/man/man1/rcup.1
index a558b20..f68cc87 100644
--- a/man/man1/rcup.1
+++ b/man/man1/rcup.1
@@ -4,13 +4,13 @@
rcup \- update and install dotfiles
.SH SYNOPSIS
-.B rcup [-v] [-q] [-t \fItag\fR] [\fIfiles...\fR]
+.B rcup [-v] [-q] [-t \fItag\fR] [-d \fIdir\fR] [\fIfiles...\fR]
.SH DESCRIPTION
This is a program to update and install personal dotfiles. These
dotfiles are managed in a separate directory. Use \fBrcup\fR to install
-files from your dotfiles directory or from host- or tag-specific
+files from your dotfiles directories or from host- or tag-specific
directories within.
See \fBDIRECTORY LAYOUT\fR for details on the directory layout.
@@ -27,7 +27,11 @@ decrease verbosity
.TP
\fB-t\fR \fITAG\fR
-install dotfiles according to tag
+install dotfiles according to TAG
+
+.TP
+\fB-d\fR \fIDIR\fR
+install dotfiles from the DIR. This can be specified multiple times.
.TP
\fIfiles...\fR
diff --git a/man/man5/rcrc.5 b/man/man5/rcrc.5
index 1032504..67dc2a3 100644
--- a/man/man5/rcrc.5
+++ b/man/man5/rcrc.5
@@ -16,9 +16,15 @@ It supports these variables:
\fBTAGS\fR
the default tags used by \fBrcup\fR\|.
+.TP
+\fBDOTFILES_DIRS\fR
+the source directories for dotfiles. The first in the list is the
+canonical source. The default value is \fI~/.dotfiles\fR\|.
+
.SH EXAMPLES
\&\fBTAGS="freebsd development email git laptop gmail notmuch"\fR
+\&\fBDOTFILES_DIRS="/home/mike/.dotfiles /usr/share/dotfiles"\fR
.SH AUTHOR