4

After discovering 'trash-put', I would like to condition myself to use it instead of 'rm' in most cases. If I just alias it that may make me feel too safe on machines without my config files though, so I came up with the following (in my .zshrc):

function rm() {
    local go_ahead
    read -q "go_ahead?Are you sure you don't want to use rms? (y/n)"
    echo ""
    if [[ "$go_ahead" == "y" ]]; then
        /bin/rm $*
    fi
}
alias rms='trash-put'

It seems to work, but I don't have a lot of experience with zsh scripting... is this a good way to do what I want?

Thanks Peter

Peter
  • 103
  • 1
  • 8
  • Probably a better question for unix.stackexchange.com – Munim Jan 30 '14 at 10:02
  • 2
    You may want to check the options `RM_STAR_SILENT` and `RM_STAR_WAIT` and perhaps use `setopt rm_star_wait` and `setopt NO_rm_star_silent`. Also this is an interesting post about scripting a safer `rm` (from people with a lot of Zsh scripting experience) http://www.zsh.org/mla/users/2014/msg00114.html – Francisco Feb 04 '14 at 08:49
  • I found this approach useful for making `exec' ask for confirmation :-) – SamB Jul 06 '14 at 19:22

1 Answers1

2

Well, why make a function and an alias and not simply:

alias rm="rm -i"

or otherwise transform your rm so it is:

function rm() {
    local go_ahead
    read -q "Are you sure you don't want to use trash-put? [y/N]"
    echo ""
    if [[ "$go_ahead" = "y" ]]; then
        /bin/rm $*
    else
        /usr/bin/env trash-put $*
    fi
}

so it runs trash-put if you do not say y.

zmo
  • 24,463
  • 4
  • 54
  • 90
  • Thanks for your answer, but I would rather not have to confirm every time I want to delete something. That's why I put the rms alias. – Peter Jan 30 '14 at 11:41
  • well, I usually use `rm` aliased to `rm -i`, and do `rm -f` when I want no confirmation – zmo Jan 30 '14 at 11:51