Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to delete current directory



On Jul 7, 11:13am, zzapper wrote:
} Subject: Re: How to delete current directory
}
} >     alias lrm='cd .. && rm -rf $OLDPWD'
} > 
} > If for any reason the "cd" were to fail, unlikely as that may be, you
} > wouldn't want to rm the wrong $OLDPWD.
} > 
} > 
} Is there are mechanism in zsh which will allow the rm -r to start off in 
} confirm mode ie "do you want to delete this file" and then choose "all"??

    unalias lrm
    function lrm {
        setopt localoptions glob_dots no_rm_star_silent
        cd .. || return
	rm -rf $OLDPWD/* && rmdir $OLDPWD
	[[ ! -d $OLDPWD ]] || { cd $OLDPWD && return 1 }
    }

I rigged it so that if you say "no" you don't even change directories.
You could even throw rm_start_wait onto the end of the setopt if you
are extra-paranoid.

Unfortunately saying "no" doesn't cause "rm" to return a failure status,
so the "rmdir" is attempted either way.

Aside to zsh-workers:  It'd be nice if I didn't have to setopt glob_dots
there, but
    rm -rf $OLDPWD/*(D)
does not trigger rm_star handling because "*(D)" != "*".  That seems a
bad thing.

-- 



Messages sorted by: Reverse Date, Date, Thread, Author