Re:Ask HN: Small scripts, hacks and automations you're proud...
by redman25 on Sunday March 12, 2023 @11:43PM
(#35130724)
On any system I'm working on I add a stupid simple script named `can` that moves items to the trash can. I can't say how many times it has saved my bacon avoiding accidental permanent deletions over using `rm`.
[ Parent
| on HN ]
Re:Ask HN: Small scripts, hacks and automations you're proud...
by pncnmnp on Monday March 13, 2023 @12:23AM
(#35131029)
Really cool idea. For macOS, I just found out about trash https://formulae.brew.sh/formula/trash
Re:Ask HN: Small scripts, hacks and automations you're proud...
by spaboleo on Monday March 13, 2023 @07:29PM
(#35144776)
One of the few aliases I always use is:
alias rm='trash -i'
It will prompt you before moving files to the trash instead of deleting them straight away on macOS.I've also added the -i flag to the following:
alias mv='mv -i -v'
alias cp='cp -i -v'
alias ln='ln -i -v'
It warns me when a file might be overwritten in the target directory and will display a short protocol of the actions performed due to the 'verbose' flag.
Re:Ask HN: Small scripts, hacks and automations you're proud...
by cywick on Thursday March 16, 2023 @01:51PM
(#35185527)
> alias rm='trash -i'
This can really backfire. Ages ago, I used to have exactly the same alias for 'rm'. After a year or two, I got so used to 'rm' not really being destructive that one late night when I was really tired, I used it on a remote system without feeling the need to carefully check the file name. That remote system, of course, did not have 'rm' aliased to a safer version...
Long story short, I strongly recommend using a different alias name (e.g., 'rem', 'rmi' or so). In this case, the worst that can happen is getting a 'command not found' message, when the alias is missing.
Re:Ask HN: Small scripts, hacks and automations you're proud...
by spaboleo on Monday March 20, 2023 @05:15AM
(#35229044)
I agree, yet I consider this to be the other way round. I treat "rm" still like a direct removal of the file and therefore use it with caution every time. Having it trash the file on my local machines is just a to me hidden fallback. But it is a very valid concern, of course.
Re:Ask HN: Small scripts, hacks and automations you're proud...
by jamescodesthing on Friday March 17, 2023 @12:11PM
(#35199011)
I use a similar thing that also handles when you forget -rf, with confirmation & stuff; https://github.com/MikeDacre/careful_rm