diff options
author | Mike Burns <mike@mike-burns.com> | 2013-08-11 15:38:06 +0200 |
---|---|---|
committer | Mike Burns <mike@mike-burns.com> | 2013-08-11 15:38:06 +0200 |
commit | 63ab42206f25e181f626ec0c7ddad045fa27846c (patch) | |
tree | 6b9ea930409ac57023b5bba71d9de12ee51d93db /bin/rcdn | |
parent | 5319a8038ef4fa1f716e33fad6628d8737ddcef0 (diff) |
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.
Diffstat (limited to 'bin/rcdn')
-rwxr-xr-x | bin/rcdn | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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 |