From 85e16216d4f95a3986ce18d3e5a4a5ed431a4ad5 Mon Sep 17 00:00:00 2001 From: The Linux Kitten Date: Sun, 9 Mar 2014 21:22:02 +0100 Subject: Add support for -v option on OpenBSD The `-v` (verbose) flag for `cp`, `ln`, and `rm` is not standard. It is simple to implement using shell functions, so introduce `cp_v`, `ln_v`, and `rm_v`. These shell functions use the existing `$VERBOSE` variable for printing, which simplifies the code and reduces the number of variables. Fixes #61. --- NEWS.md.in | 1 + bin/mkrc | 2 +- bin/rcdn | 2 +- bin/rcup | 9 +++++---- man/rcm.7 | 1 + share/rcm.sh.in | 38 +++++++++++++++++++++----------------- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/NEWS.md.in b/NEWS.md.in index b837e0a..2c0608d 100644 --- a/NEWS.md.in +++ b/NEWS.md.in @@ -8,6 +8,7 @@ rcm (@PACKAGE_VERSION@) unstable; urgency=low * BUGFIX: Support multiple -d options when given relative paths (Mike Burns). * BUGFIX: Cygwin compatibility for hostname (Mike Burns). + * BUGFIX: Support -v option on OpenBSD (Javier López). * Handle more files with spaces in their filename (Caleb Land, Pat Brisbin, Mike Burns). * Hooks in directories instead of just single executables (Pablo Olmos diff --git a/bin/mkrc b/bin/mkrc index d99cf36..3d9b749 100755 --- a/bin/mkrc +++ b/bin/mkrc @@ -82,7 +82,7 @@ for file in $files; do dest="$(destination "$DOTFILES_DIR" "$dotless" $in_host "$tag")" mkdir -p "$dest/$(dirname "$dotless")" $PRINT "Moving..." - $MV "$file" "$dest/$dotless" + mv_v "$file" "$dest/$dotless" $PRINT "Linking..." $INSTALL -d "$DOTFILES_DIR" -t "${tag:--}" "$dotless" done diff --git a/bin/rcdn b/bin/rcdn index 3550a30..2caa340 100755 --- a/bin/rcdn +++ b/bin/rcdn @@ -11,7 +11,7 @@ remove_link() { if [ "x$dest" = "x/" ]; then $VERBOSE "not a symlink, skipping: $original" elif [ -L "$dest" -o "x$sigil" = "xX" ]; then - $RM -rf "$dest" + rm_v -rf "$dest" rmdir -p "$(dirname "$original")" 2>/dev/null else remove_link "$(dirname "$dest")" "$original" diff --git a/bin/rcup b/bin/rcup index c1cdc8e..b45157b 100755 --- a/bin/rcup +++ b/bin/rcup @@ -8,7 +8,7 @@ link_or_copy() { local sigil="$1" if [ "x$sigil" = "xX" ]; then - echo "$CP" + echo "cp_v" else echo "$LN" fi @@ -20,7 +20,7 @@ link_file() { local sigil="$3" if [ -h "$dest" ]; then - $RM -f "$dest" + rm_v -f "$dest" fi action="$(link_or_copy "$sigil")" @@ -35,7 +35,7 @@ replace_file() { $DEBUG replace_file "$1" "$2" $3 - $RM -rf "$dest" + rm_v -rf "$dest" link_file "$src" "$dest" "$sigil" } @@ -126,8 +126,9 @@ handle_command_line() { done shift $(($OPTIND-1)) + LN="ln_v" if [ $always_copy -eq 1 ]; then - LN="$CP" + LN="cp_v" fi handle_common_flags rcup $version $verbosity diff --git a/man/rcm.7 b/man/rcm.7 index 1b39eae..6b69d31 100644 --- a/man/rcm.7 +++ b/man/rcm.7 @@ -245,6 +245,7 @@ and .An "Caleb Land" Aq Mt caleb@land.fm .An "Dan Croak" Aq Mt dan@thoughtbot.com .An "George Brocklehurst" Aq Mt george@thoughtbot.com +.An "Javier López" Aq Mt linux.kitten@gmail.com .An "Jordan Eldredge" Aq Mt jordaneldredge@gmail.com .An "Pablo Olmos de Aguilera Corradini" Aq Mt pablo@glatelier.org .An "Patrick Brisbin" Aq Mt pat@thoughtbot.com diff --git a/share/rcm.sh.in b/share/rcm.sh.in index bccc0a9..bcf3dce 100644 --- a/share/rcm.sh.in +++ b/share/rcm.sh.in @@ -8,16 +8,32 @@ PRINT=echo PROMPT=echo_n ERROR=echo_error VERBOSE=: -MKDIR=mkdir -LN="ln -s" -CP="cp -R" -RM=rm DEFAULT_DOTFILES_DIR="$HOME/.dotfiles" -MV=mv +MKDIR=mkdir INSTALL=rcup ROOT_DIR="$HOME" HOSTNAME="$(hostname | sed -e 's/\..*//')" +ln_v() { + $VERBOSE "'$1' -> '$2'" + ln -s "$1" "$2" +} + +cp_v() { + $VERBOSE "'$1' -> '$2'" + cp -R "$1" "$2" +} + +rm_v() { + $VERBOSE "removed '$2'" + rm $1 "$2" +} + +mv_v() { + $VERBOSE "'$1' -> '$2'" + mv "$1" "$2" +} + unset CDPATH echo_n() { @@ -61,28 +77,16 @@ handle_common_flags() { DEBUG=echo_stderr VERBOSE=echo PRINT=echo - MV="$MV -v" - RM="$RM -v" - LN="$LN -v" - CP="$CP -v" INSTALL="$INSTALL -vv" elif [ $verbosity -eq 1 ]; then DEBUG=: VERBOSE=echo PRINT=echo - MV="$MV -v" - RM="$RM -v" - LN="$LN -v" - CP="$CP -v" INSTALL="$INSTALL -v" elif [ $verbosity -eq 0 ]; then DEBUG=: VERBOSE=: PRINT=echo - MV="$MV -v" - RM="$RM -v" - LN="$LN -v" - CP="$CP -v" else DEBUG=: VERBOSE=: -- cgit v1.2.3