From 9e16a4aea0dad1909abc78b3f9bc1291917486db Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Thu, 1 Aug 2013 16:06:30 -0400 Subject: Add `mkrc -o` to install host-specific files To make it easier to manage host-specific rc files, `mkrc` now supports a `-o` option. This causes the specified file to be added to the host section named for the current machine. This option is in conflict with the `-t` option. --- NEWS.md.in | 2 ++ bin/mkrc | 25 +++++++++++++++++++------ man/mkrc.1 | 5 ++++- man/rcm.7 | 4 +--- share/rcm.sh.in | 8 ++++++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/NEWS.md.in b/NEWS.md.in index daf8108..2061768 100644 --- a/NEWS.md.in +++ b/NEWS.md.in @@ -1,6 +1,8 @@ rcm (@PACKAGE_VERSION@) unstable; urgency=low * Improved Debian handling. + * Introduce mkrc -o to install host-specific dotfiles. + -- Mike Burns Tue, 01 Aug 2013 16:43:33 +0200 rcm (0.0.2) unstable; urgency=low diff --git a/bin/mkrc b/bin/mkrc index 057c172..5a70482 100755 --- a/bin/mkrc +++ b/bin/mkrc @@ -4,10 +4,17 @@ . $RCM_LIB/rcm.sh destination() { - if [ $# -eq 2 ]; then - echo $1 + local dotfiles_dir=$1 + local dotless=$2 + local in_host=$3 + local tag=$4 + + if [ "x$tag" != "x" ]; then + echo $dotfiles_dir/tag-$tag + elif [ $in_host = 1 ]; then + echo $dotfiles_dir/host-`hostname` else - echo $1/tag-$3 + echo $dotfiles_dir fi } @@ -16,7 +23,7 @@ if [ -e $HOME/.rcrc ]; then fi if [ $# -eq 0 ]; then - echo "Usage: mkrc [-d dir] [-t tag] [-v] [-q] filename ..." + echo "Usage: mkrc [-d dir] [-t tag] [-o] [-v] [-q] filename ..." exit 1 fi @@ -26,13 +33,15 @@ done tag= verbosity=0 +in_host=0 version=0 -while getopts Vvqt:d: opt; do +while getopts Vvqot:d: opt; do case "$opt" in t) tag=$OPTARG;; v) verbosity=$(($verbosity + 1));; q) verbosity=$(($verbosity - 1));; + o) in_host=1;; d) DOTFILES_DIR=$OPTARG;; V) version=1 esac @@ -41,11 +50,15 @@ shift $(($OPTIND-1)) handle_common_flags mkrc $version $verbosity +if [ $in_host -eq 1 -a "x$tag" != "x" ]; then + $ERROR 1 "Cannot specify both -o and -t" +fi + files=$@ for file in $files; do dotless=`echo $file | sed -e "s|$DEST_DIR/||" | sed -e 's/^\.//'` - dest=`destination $DOTFILES_DIR $dotless $tag` + dest=`destination $DOTFILES_DIR $dotless $in_host $tag` mkdir -p $dest/`dirname $dotless` $MV $file $dest/$dotless $INSTALL -d $DOTFILES_DIR -t ${tag:--} $dotless diff --git a/man/mkrc.1 b/man/mkrc.1 index 2d8bbdb..69e2a04 100644 --- a/man/mkrc.1 +++ b/man/mkrc.1 @@ -6,7 +6,7 @@ .Nd bless files into a dotfile .Sh SYNOPSIS .Nm mkrc -.Op Fl vq +.Op Fl vqo .Op Fl t Ar tag .Op Fl d Ar dir .Ar files ... @@ -27,6 +27,8 @@ install dotfiles according to tag .It Fl d Ar DIR install dotfiles under the specified directory. This can be specified multiple times. +.It Fl o +install dotfiles into the host-specific directory .El .Sh FILES .Pa ~/.dotfiles @@ -34,6 +36,7 @@ multiple times. .Sh EXAMPLES .Dl mkrc ~/.vimrc .Dl mkrc -t zsh -d company-dotfiles ~/.zshrc ~/.zlogin +.Dl mkrc -o ~/.rcrc .Sh SEE ALSO .Xr lsrc 1 , .Xr rcup 1 , diff --git a/man/rcm.7 b/man/rcm.7 index 54bb79a..05ebd90 100644 --- a/man/rcm.7 +++ b/man/rcm.7 @@ -203,9 +203,7 @@ file is a popular candidate for a host-specific file, since the tags and dotfile directories listed in there are often specific to a single machine. .Pp -.Dl mkdir .dotfiles/host-`hostname` -.Dl mv .rcrc .dotfiles/host-`hostname`/rcrc -.Dl rcup +.Dl mkrc -o .rcrc . .Sh RATIONALE .Pp diff --git a/share/rcm.sh.in b/share/rcm.sh.in index c057e87..3b8b87b 100644 --- a/share/rcm.sh.in +++ b/share/rcm.sh.in @@ -6,6 +6,7 @@ DEBUG=: DEST_DIR=$HOME PRINT=echo PROMPT=echo_n +ERROR=echo_error VERBOSE=: MKDIR=mkdir LN=ln @@ -20,6 +21,13 @@ echo_n() { printf "%s " "$*" } +echo_error() { + local exit_status=$1 + shift + echo $* >&2 + exit $exit_status +} + version() { cat << EOV $1 (rcm) $VERSION -- cgit v1.2.3