summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Mike Burns <mike@mike-burns.com>2013-08-05 06:15:17 +0200
committerGravatar Mike Burns <mike@mike-burns.com>2013-08-05 06:15:17 +0200
commitfc648042ca2e753b8ecdabc5fa52aea5313c3b03 (patch)
treee69c2dba330066ef1ddc5725d97ab0b336ef5783
parent122bbf0c6da226fc7e8a7e2a8d173b3e6259f7cf (diff)
Add -C for copying files
Some files prefer to be copies instead of symlinks---for example, OpenSSH ignores symlinks. Add the `-C` option to mkrc(1) and rcup(1) to handle this. mkrc -C .ssh rcup -C ssh This does raise a synchronization problem that I do not yet know how to solve; namely, what to do when the rc file changes. Perhaps a `rcsync` command is in order; perhaps `rcup` should handle this; perhaps `rcsync` is a better name for `rcup`.
-rw-r--r--NEWS.md.in3
-rwxr-xr-xbin/mkrc20
-rwxr-xr-xbin/rcup22
-rw-r--r--man/mkrc.118
-rw-r--r--man/rcup.18
-rw-r--r--share/rcm.sh.in5
6 files changed, 48 insertions, 28 deletions
diff --git a/NEWS.md.in b/NEWS.md.in
index df52095..4c4ebb9 100644
--- a/NEWS.md.in
+++ b/NEWS.md.in
@@ -1,6 +1,7 @@
rcm (@PACKAGE_VERSION@) unstable; urgency=low
- * Exclusion and inclusion with -e and -I
+ * Exclusion and inclusion with -e and -I.
+ * Copy instead of symlink with -C.
-- Mike Burns <mburns@thoughtbot.com> Mon, 05 Aug 2013 16:43:33 +0200
diff --git a/bin/mkrc b/bin/mkrc
index d3effb8..d8ed478 100755
--- a/bin/mkrc
+++ b/bin/mkrc
@@ -35,15 +35,17 @@ tag=
verbosity=0
in_host=0
version=0
+always_copy=0
-while getopts Vvqot:d: opt; do
+while getopts CVvqot: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
+ C) always_copy=1 ;;
+ t) tag=$OPTARG ;;
+ v) verbosity=$(($verbosity + 1)) ;;
+ q) verbosity=$(($verbosity - 1)) ;;
+ o) in_host=1 ;;
+ d) DOTFILES_DIR=$OPTARG ;;
+ V) version=1 ;;
esac
done
shift $(($OPTIND-1))
@@ -54,6 +56,10 @@ if [ $in_host -eq 1 -a "x$tag" != "x" ]; then
$ERROR 1 "Cannot specify both -o and -t"
fi
+if [ $always_copy -eq 1 ]; then
+ INSTALL="$INSTALL -C"
+fi
+
files=$@
for file in $files; do
diff --git a/bin/rcup b/bin/rcup
index 37ccb2f..df9adac 100755
--- a/bin/rcup
+++ b/bin/rcup
@@ -7,12 +7,11 @@ link_file() {
local src=$1
local dest=$2
- $PRINT "linking $dest"
if [ -h $dest ]; then
- rm -f $dest
+ $RM -f $dest
fi
- $LN -s $src $dest
+ $LN $src $dest
}
replace_file() {
@@ -78,24 +77,29 @@ handle_command_line() {
local files=
local excludes=
local includes=
+ local always_copy=0
REPLACE_ALL=0
-
- while getopts VqvfiI:e:t:d: opt; do
+ while getopts CVqvfiI:e:t:d: opt; do
case "$opt" in
- e) excludes="$excludes $OPTARG";;
+ C) always_copy=1 ;;
+ d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;;
+ e) excludes="$excludes $OPTARG" ;;
f) REPLACE_ALL=1 ;;
i) REPLACE_ALL=0 ;;
- I) includes="$includes $OPTARG";;
+ I) includes="$includes $OPTARG" ;;
+ q) verbosity=$(($verbosity - 1)) ;;
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
shift $(($OPTIND-1))
+ if [ $always_copy -eq 1 ]; then
+ LN=cp
+ fi
+
handle_common_flags rcup $version $verbosity
tags=${arg_tags:-$TAGS}
diff --git a/man/mkrc.1 b/man/mkrc.1
index 05611d0..f5e1918 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 vqo
+.Op Fl Cvqo
.Op Fl t Ar tag
.Op Fl d Ar dir
.Ar files ...
@@ -18,17 +18,20 @@ different source directory.
It supports these options:
.
.Bl -tag
-.It Fl v
-increase verbosity. This can be repeated for extra verbosity.
-.It Fl q
-decrease verbosity
-.It Fl t Ar TAG
-install dotfiles according to tag
+.It Fl C
+copy instead of symlinking when installing the rc file back into your
+home directory
.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
+.It Fl q
+decrease verbosity
+.It Fl t Ar TAG
+install dotfiles according to tag
+.It Fl v
+increase verbosity. This can be repeated for extra verbosity.
.El
.Sh FILES
.Pa ~/.dotfiles
@@ -37,6 +40,7 @@ install dotfiles into the host-specific directory
.Dl mkrc ~/.vimrc
.Dl mkrc -t zsh -d company-dotfiles ~/.zshrc ~/.zlogin
.Dl mkrc -o ~/.rcrc
+.Dl mkrc -C .ssh
.Sh SEE ALSO
.Xr lsrc 1 ,
.Xr rcdn 1 ,
diff --git a/man/rcup.1 b/man/rcup.1
index 342ee6b..e8f646a 100644
--- a/man/rcup.1
+++ b/man/rcup.1
@@ -6,7 +6,7 @@
.Nd update and install dotfiles
.Sh SYNOPSIS
.Nm rcup
-.Op Fl fiqv
+.Op Fl Cfiqv
.Op Fl d Ar dir
.Op Fl e Ar excl_pat
.Op Fl I Ar excl_pat
@@ -25,10 +25,12 @@ for details on the directory layout.
.Pp
It supports these options:
.Bl -tag
+.It Fl C
+copy the files instead of symlinking them
.It Fl d Ar DIR
install dotfiles from the
-.Ar DIR
-\&. This can be specified multiple times.
+.Ar DIR .
+This can be specified multiple times.
.It Fl e Ar EXCL_PAT
do not install rc files that match
.Ar EXCL_PAT .
diff --git a/share/rcm.sh.in b/share/rcm.sh.in
index 6dae15b..186f3a2 100644
--- a/share/rcm.sh.in
+++ b/share/rcm.sh.in
@@ -9,7 +9,7 @@ PROMPT=echo_n
ERROR=echo_error
VERBOSE=:
MKDIR=mkdir
-LN=ln
+LN="ln -s"
RM=rm
DEFAULT_DOTFILES_DIR=$HOME/.dotfiles
MV=mv
@@ -60,6 +60,7 @@ handle_common_flags() {
PRINT=echo
MV="$MV -v"
RM="$RM -v"
+ LN="$LN -v"
INSTALL="$INSTALL -vv"
elif [ $verbosity -eq 1 ]; then
DEBUG=:
@@ -67,6 +68,7 @@ handle_common_flags() {
PRINT=echo
MV="$MV -v"
RM="$RM -v"
+ LN="$LN -v"
INSTALL="$INSTALL -v"
elif [ $verbosity -eq 0 ]; then
DEBUG=:
@@ -74,6 +76,7 @@ handle_common_flags() {
PRINT=echo
MV="$MV -v"
RM="$RM -v"
+ LN="$LN -v"
else
DEBUG=:
VERBOSE=: