From 63ab42206f25e181f626ec0c7ddad045fa27846c Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Sun, 11 Aug 2013 15:38:06 +0200 Subject: rcdn only removes symlinks Picture this case: % ls -l ~/.a ~/.a -> ~/.dotfiles/a % tree ~/.dotfiles/a a `-- b `-- c `-- d `-- foo Ideally we would want `~/.a/b/c/d/foo` to be the symlink, and the rest to be actual directories. However, some people did it differently. Running `rcdn` on the above would previously have removed `foo` from `~/.dotfiles`. Now, it removes `~/.a` and nothing more. --- bin/rcdn | 17 +++++++++++++++-- man/rcdn.1 | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bin/rcdn b/bin/rcdn index a7fb81d..99812aa 100755 --- a/bin/rcdn +++ b/bin/rcdn @@ -3,6 +3,20 @@ : ${RCM_LIB:=`dirname $0`/../share/rcm} . $RCM_LIB/rcm.sh +remove_link() { + local dest=$1 + local original=$2 + + if [ x$dest = "x/" ]; then + $VERBOSE "not a symlink, skipping: $original" + elif [ -L $dest ]; then + $RM -rf $dest + rmdir -p `dirname $original` 2>/dev/null + else + remove_link `dirname $dest` $original + fi +} + handle_command_line() { local arg_tags= local verbosity=0 @@ -58,6 +72,5 @@ for dest_and_src in `lsrc $LS_ARGS`; do dest=`echo $dest_and_src | sed 's/:.*//'` src=`echo $dest_and_src | sed 's/.*://'` - $RM -rf $dest - rmdir -p `dirname $dest` 2>/dev/null + remove_link $dest $dest done diff --git a/man/rcdn.1 b/man/rcdn.1 index 9007783..d61707e 100644 --- a/man/rcdn.1 +++ b/man/rcdn.1 @@ -13,7 +13,7 @@ .Op Fl t Ar tag .Op Ar files ... .Sh DESCRIPTION -This program will remove all the rc files that the +This program will remove all the rc file symlinks that the .Xr rcm 7 suite knows about. This can be further controlled with the .Fl t -- cgit v1.2.3