4 ms·
> trash a.txt b.png moves `a.txt` and `b.png` to the trash. Supports macOS and Linux. The way you’re doing it trashes files sequentially, meaning you hear the
by latexr 1y ago
> trash a.txt b.png moves `a.txt` and `b.png` to the trash. Supports macOS and Linux.
The way you’re doing it trashes files sequentially, meaning you hear the trashing sound once per file and ⌘Z in the Finder will only restore the last one. You can improve that (I did it for years) but consider just using the `trash` commands which ships with macOS. Doesn’t use the Finder, so no sound and no ⌘Z, but it’s fast, official, and still allows “Put Back”.
> jsonformat takes JSON at stdin and pretty-prints it to stdout.
Why prioritise node instead of jq? The latter is considerably less code and even comes preinstalled with macOS, now.
> uuid prints a v4 UUID. I use this about once a month.
Any reason to not simply use `uuidgen`, which ships with macOS and likely your Linux distro?
https://www.man7.org/linux/man-pages/man1/uuidgen.1.html https://www.man7.org/linux/man-pages/man1/uuidgen.1.html
- derintegrative 1y agoOn Linux you also have % cat /proc/sys/kernel/random/uuid 464a4e91-5ce4-47b6-bb09-8a60fde572fb
- sedatk 1y agoand it's `New-Guid` in PowerShell.
- rbonvall 1y agoPython also pretty-prints out of the box: $ echo '{ "hello": "world" }' | python3 -m json.tool { "hello": "world" }
- tester457 1y agoI am not the author, but my bet is that he didn't know of its existence. The best part about sharing your config or knowledge is that someone will always light up your blind spots.
- gigatexal 1y agoExactly! I didn’t know macOS ships JQ or the uuidgen tool. Very cool
- _kb 1y agoOr more abstractly: post anything to the internet and people will always detail how you’re wrong. Sometimes that can be useful.
- byryan 1y agoThat seems to be especially true on HN. Other forums there is some of that as well, but HN it seems nearly every single comment section is like 75% (random number) pointing out faults in the posted article.
- bdangubic 1y agoI find that endearing for two reasons: - either critique is solid and I learn something - or commenter is clueless which makes it entertaining there is very seldom a “middle”
- gaudystead 1y agoAlthough I normally loathe pedantic assholes, I've found the ones on HN seem to be more tolerable because they typically know they'll have to back up what they're saying with facts (and ideally citations). I've found that pedantic conversations here seem to actually have a greater potential for me to learn something from them than other forums/social platforms. On other platforms, I see someone providing a pedantic response and I'll just keep moving on, but on HN, I get curious to not only see who wins the nerd fight, but also that I might learn at least one thing along the way. I like that it's had an effect on how I engage with comment sections.
- dylan604 1y agoalso possible (even though I've seen the author's response to not knowing) is that the scripts were written before native was included. at that point, the muscle memory is just there. I know I have a few scripts like that myself
- t_mahmood 1y ago> The best part about sharing your config or knowledge is that someone will always light up your blind spots. Yes! I will take this as a chance to thank every people who shared their knowledge on the Internet. You guys are so freaking awesome! You are always appreciated. A big chunk of my whole life's learning came from all the forums that I used to scour through, hours after hour! Because these awesome people always sharing their knowledge, and someone adding more. That's what made Internet, Internet. And all is now almost brink of loss, because of greedy corporates. This habit also helped me with doom-scrolling. I sometimes, do doomscroll, but I can catch it quickly and snap out of it. Because, my whole life, I always jumped in to the rabbit holes, and actually read those big blog posts, where you had those `A-ha` moments, "Oohh, I can use that", "Ahh, that's clever!". When, browsing, do not give me that, by brain actually triggers, "What are you doing?" Later, I got lazy, which I am still paying for. But I am going to get out of it. Never stop jumping into those rabbit holes!! Well, obviously, not always it's a good rabbit hole, but you'll probably come out wiser.
- shortrounddev2 1y ago> Why prioritise node instead of jq? In powershell I just do > echo '{"foo": "bar"} | ConvertFrom-Json | ConvertTo-Json { "foo": "bar" } But as a function
- mmmm2 1y ago`trash` is good to know, thanks! I'd been doing: "tell app \"Finder\" to move {%s} to trash" where %s is a comma separated list of "the POSIX file <path-to-file>".
- deleted 1y ago[deleted]
- gcanyon 1y agoOooh, I just suggested in another comment that using applescript would be possible. I didn't think it would be this easy though.
- Grimburger 1y agoShoutout to rip as an alternative to rm and trash: https://github.com/nivekuil/rip https://github.com/nivekuil/rip
- frumplestlatz 1y agoFor trash on macOS, I recommend https://github.com/ali-rantakari/trash https://github.com/ali-rantakari/trash Does all the right things and works great. There’s a similar tool that works well on Linux/BSDs that I’ve used for years, but I don’t have my FreeBSD desktop handy to check.
- deleted 1y ago[deleted]
- blacksmith_tb 1y agoThe trash command for macOS that's being talked about above is native in the OS now, since v14 according to its manpage, though I see it may have really been v15[1] 1: https://mjtsai.com/blog/2025/08/26/the-trash-command/ https://mjtsai.com/blog/2025/08/26/the-trash-command/
- YouAreWRONGtoo 1y agoInstead of trash, reimplementing rm (to only really delete after some time or depending on resource usage or to shred of you are paranoid if the goal is to really delete something) or using zfs makes much more sense.
- orhmeh09 1y agoI can't imagine a scenario where I would want to reimplement rm just for this.
- YouAreWRONGtoo 1y ago[flagged]
- latexr 1y agohttps://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html > Be kind. Don't be snarky. Converse curiously; don't cross-examine. Edit out swipes. Instead of being rude to a fellow human making an inoffensive remark, you could’ve spent your words being kind and describing the scenario you claim exists. For all you know, maybe they did ask ChatGPT and were unconvinced by the answer. As a side note, I don’t even understand how your swipe would make sense. If anything, needing ChatGPT is what demonstrates a lack of imagination (having the latter you don’t need the former).
- YouAreWRONGtoo 1y agoWhat makes you think I need ChatGPT, since I just wondered whether ChatGPT was as stupid, since obviously I do know why that would be useful?
- thiht 1y agoHow is this better?
- alanh 1y agoThe idea of changing what 'rm' does sets off all of my "foot-gun" alarm bells
- idoubtit 1y agoOther examples where native features are better than these self-made scripts... > vim [...] I select a region and then run :'<,'>!markdownquote Just select the first column with ctrl-v, then "i> " then escape. That's 4 keys after the selection, instead of 20. > u+ 2025 returns ñ, LATIN SMALL LETTER N WITH TILDE `unicode` is widely available, has a good default search, and many options. BTW, I wonder why "2025" matched "ñ". unicode ñ U+00F1 LATIN SMALL LETTER N WITH TILDE UTF-8: c3 b1 UTF-16BE: 00f1 Decimal: ñ Octal: \0361 > catbin foo is basically cat "$(which foo)" Since the author is using zsh, `cat =foo` is shorter and more powerful. It's also much less error-prone with long commands, since zsh can smartly complete after =. I use it often, e.g. `file =firefox` or `vim =myscript.sh`.
- oneeyedpigeon 1y ago> `unicode` is widely available It's not installed by default on macOS or Ubuntu, for me.
- pmontra 1y agoYou are right but $ unicode Command 'unicode' not found, but can be installed with: sudo apt install unicode and it did. So it really was available. That's Debian 11.
- true_religion 1y agoTrash command first appeared in macOS 14.0, which was 2023.
- gcanyon 1y agoI believe it would be possible to execute an applescript to tell the finder to delete the files in one go. It would theoretically be possible to construct/run the applescript directly in a shell script. It would be easier (but still not trivial) to write an applescript file to take the file list as an argument to then delete when calling from the shell.
- latexr 1y agoIt’s not theoretical, and it is trivial. Like I said, I did exactly that for years. Specifically, I had a function in my `.zshrc` to expand all inputs to their full paths, verify and exclude invalid arguments, trash the rest in one swoop, then show me an error with the invalid arguments, if any.
- deleted 1y ago[deleted]
- energy123 1y agoI do `mv a.txt /tmp` instead of `rm`.
- lkbm 1y ago> Why prioritise node instead of jq? The latter is considerably less code and even comes preinstalled with macOS, now. That was my thought. I use jq to pretty print json. What I have found useful is j2p and p2j to convert to/from python dict format to json format (and pretty print the output). I also have j2p_clip and p2j_clip, which read from and then write to the system clipboard so I don't have to manually pipe in and out. > Any reason to not simply use `uuidgen`, which ships with macOS and likely your Linux distro? I also made a uuid, which just runs uuidgen, but then trims the \n. (And maybe copied to clipboard? It was at my old job, and I don't seem to have saved it to my personal computer.)