News for hackers. Stuff that matters.
Re:Scripts I wrote that I use all the time by latexr on Wednesday October 22, 2025 @03:05PM (#45673681)
> 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

Re:Scripts I wrote that I use all the time by sedatk on Wednesday October 22, 2025 @04:21PM (#45674658)
and it's `New-Guid` in PowerShell.
Re:Scripts I wrote that I use all the time by rbonvall on Wednesday October 22, 2025 @04:27PM (#45674729)
Python also pretty-prints out of the box:

    $ echo '{ "hello": "world" }' | python3 -m json.tool
    {
        "hello": "world"
    }
Re:Scripts I wrote that I use all the time by tester457 on Wednesday October 22, 2025 @04:28PM (#45674740)
I 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.

Re:Scripts I wrote that I use all the time by _kb on Wednesday October 22, 2025 @07:25PM (#45676431)
Or more abstractly: post anything to the internet and people will always detail how you’re wrong. Sometimes that can be useful.
Re:Scripts I wrote that I use all the time by byryan on Wednesday October 22, 2025 @08:34PM (#45676892)
That 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.
Re:Scripts I wrote that I use all the time by gaudystead on Wednesday October 22, 2025 @09:29PM (#45677193)
Although 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.

Re:Scripts I wrote that I use all the time by password4321 on Wednesday October 22, 2025 @09:53PM (#45677333)
And the worst of it gets flagged and even dead-ed so most skip it after a bit, as I assumed would happen recently

https://news.ycombinator.com/item?id=45649771

Re:Scripts I wrote that I use all the time by imcritic on Thursday October 23, 2025 @04:59AM (#45679753)
Yes, flagging mechanism on HN is evil.
Re:Scripts I wrote that I use all the time by kergonath on Thursday October 23, 2025 @07:47AM (#45680750)
It’s a blunt tool, but quite useful for posts. I read most dead posts I come across and I don’t think I ever saw one that was not obviously in violation of several guidelines.

OTOH I don’t like flagging stories because good ones get buried regularly. But then HN is not a great place for peaceful, nuanced discussion and these threads often descend into mindless flame wars, which would bury the stories even without flagging.

So, meh. I think flagging is a moderately good thing overall but it really lacks in subtlety.

Re:Scripts I wrote that I use all the time by freedomben on Thursday October 23, 2025 @02:03PM (#45684885)
Agreed, flagging for comments seems to function pretty well for the most part, and the vouch option provided a recourse for those that shouldn't have been killed.

On stories however, I think the flag system is pretty broken. I've seen so many stories that get flagged because people find them annoying (especially AI-related things) or people assume it will turn into a flame war, but it ends up burying important tech news. Even if the flags are reversed, the damage is usually done because the story fell off the front page (or further) and gets very little traction after that.

Re:Scripts I wrote that I use all the time by imcritic on Friday October 24, 2025 @06:12AM (#45692949)
Just imagine this comment of yours would get flagged. Was it something very valuable and now the discussion is lacking something important? Surely not, but how would you feel? So what that you have some not so mild and not so "pleasant" opinion on something - why flag the comment? Just let people downvote it!
Re:Scripts I wrote that I use all the time by MyOutfitIsVague on Thursday October 23, 2025 @10:29AM (#45682211)
I have showdead on, and almost every single flagged post I've seen definitely deserves it. Every time it wasn't "deserved", the person simply took an overly aggressive tone for no real reason.

In short, I've never seen somebody flagged simply for having the wrong opinion. Even controversial opinions tend to stay unflagged, unless they're incredibly dangerous or unhinged.

Re:Scripts I wrote that I use all the time by lolc on Thursday October 23, 2025 @11:05AM (#45682693)
I've seen a few dead posts where there was an innocent misunderstanding or wrong assumption. In those cases it would have been beneficial to keep the post visible and post a response, so that readers with similarly mistaken assumptions could have seen a correction. Small minority of dead posts though. They can be vouched for actually but of course this is unlikely to happen.

I agree that most dead posts would be a distraction and good to have been kept out.

Re:Scripts I wrote that I use all the time by nosianu on Thursday October 23, 2025 @04:40AM (#45679624)
> 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).

Can you back this up with data? ;-)

I see citations and links to sources about as little as on reddit around here.

The difference I see is in the top 1% comments, which exist in the first place, and are better on average (but that depends on what other forums or subreddits you compare it to, /r/AskHistorians is pretty good for serious history answers for example), but not in the rest of the comments. Also, less distractions, more staying on topic, the joke replies are punished more often and are less frequent.

Re:Scripts I wrote that I use all the time by bdangubic on Wednesday October 22, 2025 @08:43PM (#45676937)
I 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”

Re:Scripts I wrote that I use all the time by byryan on Wednesday October 22, 2025 @08:58PM (#45677022)
Yea I don't particularly mind it, just an interesting thing about HN compared to many other forums.
Re:Scripts I wrote that I use all the time by Schiphol on Thursday October 23, 2025 @03:42AM (#45679270)
*fora
Re:Scripts I wrote that I use all the time by Mawr on Thursday October 23, 2025 @07:29PM (#45688799)
That's a sampling bias. You're not seeing the opinions of every single person who has viewed an article, just the opinions of those who have bothered to comment.

People who agree with an article will most likely just upvote. Hardly anyone ever bothers to comment to offer praise, so most comments that you end up seeing are criticisms.

Re:Scripts I wrote that I use all the time by inanutshellus on Wednesday October 22, 2025 @09:05PM (#45677060)
This is, incidentally, codified as Cunningham's Law.

https://meta.wikimedia.org/wiki/Cunningham%27s_Law

...aaand less directly (though referenced in the wikipedia article)...

https://xkcd.com/386/

Re:Scripts I wrote that I use all the time by mlrtime on Thursday October 23, 2025 @07:45AM (#45680734)
True true, one of my favorite things is watching the shorts on home improvement or 'hacks' and sure enough there is always multiple comments saying why it won't work and why its not the right way. Just as entertaining as the video.
Re:Scripts I wrote that I use all the time by gigatexal on Wednesday October 22, 2025 @06:08PM (#45675765)
Exactly! I didn’t know macOS ships JQ or the uuidgen tool. Very cool
Re:Scripts I wrote that I use all the time by dylan604 on Wednesday October 22, 2025 @08:52PM (#45676997)
also 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
Re:Scripts I wrote that I use all the time by t_mahmood on Thursday October 23, 2025 @06:21AM (#45680269)
> 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.

Re:Scripts I wrote that I use all the time by shortrounddev2 on Wednesday October 22, 2025 @04:51PM (#45674987)
> Why prioritise node instead of jq?

In powershell I just do

    > echo '{"foo": "bar"} | ConvertFrom-Json | ConvertTo-Json
    {
        "foo": "bar"
    }
But as a function
Re:Scripts I wrote that I use all the time by mmmm2 on Wednesday October 22, 2025 @05:17PM (#45675260)
`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>".
Re:Scripts I wrote that I use all the time by gcanyon on Thursday October 23, 2025 @01:21AM (#45678399)
Oooh, I just suggested in another comment that using applescript would be possible. I didn't think it would be this easy though.
Re:Scripts I wrote that I use all the time by Grimburger on Wednesday October 22, 2025 @05:35PM (#45675463)
Shoutout to rip as an alternative to rm and trash:

https://github.com/nivekuil/rip

Re:Scripts I wrote that I use all the time by frumplestlatz on Wednesday October 22, 2025 @06:02PM (#45675713)
For trash on macOS, I recommend 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.

Re:Scripts I wrote that I use all the time by blacksmith_tb on Thursday October 23, 2025 @12:37PM (#45683907)
The 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/

Re:Scripts I wrote that I use all the time by YouAreWRONGtoo on Wednesday October 22, 2025 @06:14PM (#45675845)
Instead 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.
Re:Scripts I wrote that I use all the time by orhmeh09 on Wednesday October 22, 2025 @07:17PM (#45676366)
I can't imagine a scenario where I would want to reimplement rm just for this.
Re:Scripts I wrote that I use all the time by YouAreWRONGtoo on Thursday October 23, 2025 @04:34AM (#45679579)
That just means you lack imagination, because ChatGPT can tell you in 10 seconds.
Re:Scripts I wrote that I use all the time by latexr on Thursday October 23, 2025 @04:58AM (#45679747)
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).

Re:Scripts I wrote that I use all the time by YouAreWRONGtoo on Thursday October 23, 2025 @10:42AM (#45682390)
What 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?
Re:Scripts I wrote that I use all the time by thiht on Thursday October 23, 2025 @04:38AM (#45679616)
How is this better?
Re:Scripts I wrote that I use all the time by alanh on Wednesday October 29, 2025 @12:06AM (#45742503)
The idea of changing what 'rm' does sets off all of my "foot-gun" alarm bells
Re:Scripts I wrote that I use all the time by idoubtit on Wednesday October 22, 2025 @08:29PM (#45676857)
Other 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: &#241; 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`.

Re:Scripts I wrote that I use all the time by oneeyedpigeon on Thursday October 23, 2025 @05:40AM (#45680001)
> `unicode` is widely available

It's not installed by default on macOS or Ubuntu, for me.

Re:Scripts I wrote that I use all the time by pmontra on Thursday October 23, 2025 @09:49AM (#45681799)
You 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.
Re:Scripts I wrote that I use all the time by true_religion on Thursday October 23, 2025 @12:00AM (#45678048)
Trash command first appeared in macOS 14.0, which was 2023.
Re:Scripts I wrote that I use all the time by gcanyon on Thursday October 23, 2025 @01:20AM (#45678389)
I 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.
Re:Scripts I wrote that I use all the time by latexr on Thursday October 23, 2025 @04:21AM (#45679493)
It’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.
Re:Scripts I wrote that I use all the time by energy123 on Thursday October 23, 2025 @04:34AM (#45679586)
I do `mv a.txt /tmp` instead of `rm`.
Re:Scripts I wrote that I use all the time by lkbm on Thursday October 23, 2025 @12:02PM (#45683434)
> 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.)

Re:Scripts I wrote that I use all the time by derintegrative on Thursday October 23, 2025 @02:51PM (#45685373)
On Linux you also have

    % cat /proc/sys/kernel/random/uuid
    464a4e91-5ce4-47b6-bb09-8a60fde572fb