Rm confirmation in zsh

After detecting 'trash-put', I would prefer to use it instead of 'rm' in most cases. If I'm just an alias that can make me feel too confident on machines without my configuration files, 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'

This seems to work, but I don't have much experience with zsh scripts ... is this a good way to do what I want?

Thanks Peter

+4
source share
1 answer

Well, why create a function and an alias, and not just:

alias rm="rm -i"

or else convert your rm so that it:

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
}

therefore it launches trash-putif you do not say y.

+2
source

Source: https://habr.com/ru/post/1524465/


All Articles