Prezto: Do not use rm's -i options by default

Created on 19 Jun 2012  Â·  31Comments  Â·  Source: sorin-ionescu/prezto

I don't think that it is a good idea to alias rm to rm -i by default, because it is annoying and therefore users will just enter y without reading the name of the prompted file, or they will just start using the -f options.
I personally think that this is very counterproductive.

Discussion Idea

Most helpful comment

@sorin-ionescu It seems like the main argument for keeping this is to err on the side of caution, but the result is quite the opposite: prezto users will get used to being sloppy and careless and can do serious damage on other computers.

If you're on a system that doesn't have it, and you rm, it immediately starts deleting and you're wondering what's going on.

Many users are used to SSH'ing into different systems; so using lots of different systems, sometimes without personalized user accounts (including aliases) set up, is rather common.

Instead, use e.g. alias rmi='rm -i' and learn to use that one. If that isn't set up on a different system, you didn't accidentally delete files and can always fall back to typing the full command.

(http://superuser.com/a/384770)

The rm='rm -i' alias is an horror because after a while using it, you will expect rm to prompt you by default before removing files. Of course, one day you'll run it with an account that hasn't that alias set and before you understand what's going on, it is too late.

(http://superuser.com/a/382498/594373)


Edit: BTW, anyone who wants to follow that suggestion can add this to their .zshrc:

alias cp='nocorrect cp'
alias ln='nocorrect ln'
alias mv='nocorrect mv'
alias rm='nocorrect rm'
alias cpi="${aliases[cp]:-cp} -i"
alias lni="${aliases[ln]:-ln} -i"
alias mvi="${aliases[mv]:-mv} -i"
alias rmi="${aliases[rm]:-rm} -i"

All 31 comments

@Poapfel Your reasons to remove -i are biased. It's annoying to _you_, and _you_ will probably just enter y or use -f blindly. I don't, on the contrary I happen to like this alias (it protected me more than once from deleting the wrong file), and I'm pretty sure that @sorin-ionescu is with me here, or he would have removed the alias long ago.

A simple cost-benefit consideration also speaks for this alias, because it can protect users who want to be protected (i.e. don't blindly accept prompts or use -f) from potentially disastrous mistakes, while other users can easily overwrite this safety measure with -f with almost no cost at their own risk.

So definitely -1 for removing the alias.

If any action is to be taken, I'd vote for a zstyle:module:utility:rm:interactive configuration switch to disable this aliases (which is off by default). A similar switch could also be used for the ln, mv and cp aliases.

To quickly fix issues for yourself, either unalias rm at the end of your .zshrc, or fork this project and remove the alias from modules/utility/init.zsh.

@Poapfel: I also happen to read UAC prompts on Windows. These are useful in that they protect you from unwanted activity if _you want to be protected_.

If you simply ignore and overrule any such security measure none of these measures is ever going to help you, and in that sense really annoying. But there are users that want to be protected, me being one of them :)

@Poapfel, based on how many times I have shot myself in the foot by removing the wrong file, I am not inclined to approve your request. Don't be in a hurry. Read your prompts.

Sorry to necro-post, but I want to mention that ghost isn't alone. I'm changing my local config as well to remove the confirmation. If nothing else, consider making it configurable.

I've used rm without confirmation for a long time and I'm quite happy with that. For myself, I'm trying to minimize the amount of (negative) surprises I have when switching to prezto from a long history of bash usage and this is one change that I'm doing to help with that.

You can easily add alias rm=nocorrect rm to your .zshrc file. Or just unalias rm. There's no need to make any change on prezto.

Thanks for the suggestion -- I have indeed done just that after my comment. (and the same thing for mv as I discovered shortly afterward).

Also, sorry to to necro-post but I just switched to prezto and this default is the single biggest annoyance I found with it (speaks for prezto so far, doesn't it?). Also, due to its rather thin documentation, it took me a while to find this issue. Just wanted to comment on it.

I am inclined to keep it. I shot myself too many times in the foot. There is not a big protest against it.

Well, no problem. I managed to find the way to turn it off eventually. Apparently there are more people out there that need to be safeguarded from their own actions than I thought... ;P

I was also really annoyed that it's like this by default.

+1 to disabling it by default or at least make it obviously configurable in the settings somewhere, as some plugins are in the .zprestorc file.

Y+1 disable or making obvious the default. I was confused by this for awhile as well. At least state it somewhere obvious because I couldn't figure out why it kept prompting me when typing rm without the -i.

It stays. Don't be this guy.

@sorin-ionescu There are saner settings available to avoid that. For example, warn if user tries to rm -rf any folder not in his home. Besides, this settings would do anything against rm -rf, the _force_ would do it anyway.

If you feel so strongly about it (which is a matter of personal taste, can't be discussed and, after all, you're the project's owner), I'd recommend at least documenting it clearly somewhere in the settings. Less intrusive things are stated there.

Asking for confirmation is good user experience.

Changing the default behaviour of a common shell function without mentioning
how to reverse it is bad user experience. However, it is of course entirely
your decision as project owner.
On Sat, 16 Apr 2016 at 18:07 Sorin Ionescu [email protected] wrote:

Asking for confirmation is good user experience.

—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/sorin-ionescu/prezto/issues/205#issuecomment-210847218

I didn't think it needs documenting since you notice it the first time you try it. Why is it working differently? Just check the alias.

$ alias rm
rm='nocorrect rm -i'

It took me months of being more irritated than usual before I realized what prezto was doing here, and I'm still trying to find a sane way to turn it off. There's no question that there should be a setting and/or documentation alerting the user that this is going to happen.

@jedmund putting 'unalias rm' in your .zshrc should work, btw. best fix I've got right now.

Was just trying to copy a directory of files over an existing directory ("cp -vfr dir1 dir2") and didn't understand at first why I was still getting "Overwrite y/n?" prompts for every single file despite the "-f".

These aliases should absolutely be disabled by default. If you find yourself deleting or overwriting files you didn't mean to all the time, you're entirely free to enable them on your own. Please don't push it on everyone else just because you think it's better to be (extremely) safe than sorry. This "feature" produces unexpected behaviour from a basic system tool and that is never a good idea IMO. I imagine it's certainly going to cause problems for anyone that uses cp -f in a shell script and finds it waiting for user input... same thing for rm, which has also been annoying me with these prompts.

@joaquinlpereyra Thanks! Thats more elegant than what I was doing, which was just re-aliasing to the regular command with a space.

@joaquinlpereyra not sure how my config differs (OSX), but I had to put the unalias commands in .zshrc because putting them in .zpreztorc resulted in no such hash table element: rm.

@mateogianolio You're right. I got the name of the file wrong. You should put it in .zshrc :)

@sorin-ionescu It seems like the main argument for keeping this is to err on the side of caution, but the result is quite the opposite: prezto users will get used to being sloppy and careless and can do serious damage on other computers.

If you're on a system that doesn't have it, and you rm, it immediately starts deleting and you're wondering what's going on.

Many users are used to SSH'ing into different systems; so using lots of different systems, sometimes without personalized user accounts (including aliases) set up, is rather common.

Instead, use e.g. alias rmi='rm -i' and learn to use that one. If that isn't set up on a different system, you didn't accidentally delete files and can always fall back to typing the full command.

(http://superuser.com/a/384770)

The rm='rm -i' alias is an horror because after a while using it, you will expect rm to prompt you by default before removing files. Of course, one day you'll run it with an account that hasn't that alias set and before you understand what's going on, it is too late.

(http://superuser.com/a/382498/594373)


Edit: BTW, anyone who wants to follow that suggestion can add this to their .zshrc:

alias cp='nocorrect cp'
alias ln='nocorrect ln'
alias mv='nocorrect mv'
alias rm='nocorrect rm'
alias cpi="${aliases[cp]:-cp} -i"
alias lni="${aliases[ln]:-ln} -i"
alias mvi="${aliases[mv]:-mv} -i"
alias rmi="${aliases[rm]:-rm} -i"

@belak What do yo think of @dbmrq's suggestion?

FWIW, I'm in full agreement that setting the prompt to always fire will train people to ignore it, and also in agreement that it was a bit of an annoyance until I figured out it was a prezto module doing it. When you're new to zsh in general plus a framework on top of it, figuring out what does what is hard enough without flipping defaults.

Since it seems you're looking at this again, why not separate out those particular aliases (the ones @dbmrq mentions) into a "safeops" type module, and--assuming you still feel strongly--load it by default right after utility?

That seems like a straightforward step towards making it both more obvious and configurable for the user without sacrificing any values mentioned, and probably easier than implementing a flag.

Thanks to everyone for weighing in! Sorry it's taken me so long to get to this.

I'm not really sure what I want to do with this. On one hand, it forms bad habits (people often resort to adding -f to ignore the prompt which is very bad) and can end up relying on it so when it isn't there it causes problems... But on the other hand, people who are legitimately using this shouldn't expect it to disappear from under their feet. Especially because the current proposal asks to disable a prompt that confirms you want to delete files.

So, here are my suggestions:

  • Add the *i aliases suggested by @dbmrq above
  • Add a safeops option (a variation on what @geoelectric suggested) or something similar which will add -i to the above commands (not sure if this should default on or off... my current opinion is that we shouldn't change the default behavior)

I have mixed opinions on changing the default behavior for something that could potentially cause data loss for people who are using the same commands, but I'm still open to being convinced on that.

Not sure if all versions of rm have this option, but with standard GNU rm on Ubuntu 16.04, there is a -I flag (capital i) that will "prompt once when removing more than three files, or when removing recursively". If the -i flag _must_ be a default, might I suggest using this option instead? That way, removing one file will not bug the user, but trying to remove an entire directory will, and even then it only asks once (instead of asking about every single file in the directory).

I like that @gpanders but I don't think OSX or BSD support that option.

@belak

I have mixed opinions on changing the default behavior for something that could potentially cause data loss for people who are using the same commands

So you have to chose between potentially causing data loss for the limited number of people who already use Prezto or potentially causing data loss for the unlimited number of people who may still use Prezto in the future. I think the first option is better.

I agree that this shouldn't disappear from under people's feet, though. Traditionally I guess this would be fixed with the release of a new major version, so people who were upgrading to Prezto 2.0.0 would know there are breaking changes and look into them before upgrading. Prezto doesn't seem to use any kind of versioning though.

This has been resolved by #1375 and aad91beb3c60bab04a09a10fa56c56b469251cd3.

A new option has been added by @samcv which allows you to disable safe-ops by default. The default behavior will not be changing at this time. There have also been a new set of aliases added (rmi, lni, etc) which are explicit about what they do.

Thanks to everyone for your feedback!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daiyanze picture daiyanze  Â·  4Comments

mischaboldy picture mischaboldy  Â·  3Comments

EllieRagone picture EllieRagone  Â·  4Comments

jeffwidman picture jeffwidman  Â·  3Comments

kud picture kud  Â·  3Comments