summaryrefslogtreecommitdiff
path: root/bin/mkrc
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 /bin/mkrc
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.
Diffstat (limited to 'bin/mkrc')
-rwxr-xr-xbin/mkrc30
1 files changed, 20 insertions, 10 deletions
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