Most active commenters
  • (3)

←back to thread

756 points speckx | 27 comments | | HN request time: 0.818s | source | bottom
1. latexr ◴[] No.45673681[source]
> 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

replies(12): >>45674658 #>>45674729 #>>45674740 #>>45674987 #>>45675260 #>>45675463 #>>45675713 #>>45675845 #>>45676857 #>>45678048 #>>45678389 #>>45678522 #
2. sedatk ◴[] No.45674658[source]
and it's `New-Guid` in PowerShell.
3. rbonvall ◴[] No.45674729[source]
Python also pretty-prints out of the box:

    $ echo '{ "hello": "world" }' | python3 -m json.tool
    {
        "hello": "world"
    }
4. tester457 ◴[] No.45674740[source]
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.

replies(3): >>45675765 #>>45676431 #>>45676997 #
5. shortrounddev2 ◴[] No.45674987[source]
> Why prioritise node instead of jq?

In powershell I just do

    > echo '{"foo": "bar"} | ConvertFrom-Json | ConvertTo-Json
    {
        "foo": "bar"
    }
But as a function
6. mmmm2 ◴[] No.45675260[source]
`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>".
replies(2): >>45675433 #>>45678399 #
7. ◴[] No.45675433[source]
8. Grimburger ◴[] No.45675463[source]
Shoutout to rip as an alternative to rm and trash:

https://github.com/nivekuil/rip

9. frumplestlatz ◴[] No.45675713[source]
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.

replies(1): >>45676143 #
10. gigatexal ◴[] No.45675765[source]
Exactly! I didn’t know macOS ships JQ or the uuidgen tool. Very cool
11. YouAreWRONGtoo ◴[] No.45675845[source]
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.
replies(1): >>45676366 #
12. ◴[] No.45676143[source]
13. orhmeh09 ◴[] No.45676366[source]
I can't imagine a scenario where I would want to reimplement rm just for this.
14. _kb ◴[] No.45676431[source]
Or more abstractly: post anything to the internet and people will always detail how you’re wrong. Sometimes that can be useful.
replies(2): >>45676892 #>>45677060 #
15. idoubtit ◴[] No.45676857[source]
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`.

16. byryan ◴[] No.45676892{3}[source]
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.
replies(2): >>45676937 #>>45677193 #
17. bdangubic ◴[] No.45676937{4}[source]
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”

replies(1): >>45677022 #
18. dylan604 ◴[] No.45676997[source]
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
19. byryan ◴[] No.45677022{5}[source]
Yea I don't particularly mind it, just an interesting thing about HN compared to many other forums.
replies(1): >>45679270 #
20. inanutshellus ◴[] No.45677060{3}[source]
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/

21. gaudystead ◴[] No.45677193{4}[source]
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.

replies(1): >>45677333 #
22. password4321 ◴[] No.45677333{5}[source]
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

23. true_religion ◴[] No.45678048[source]
Trash command first appeared in macOS 14.0, which was 2023.
24. gcanyon ◴[] No.45678389[source]
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.
25. gcanyon ◴[] No.45678399[source]
Oooh, I just suggested in another comment that using applescript would be possible. I didn't think it would be this easy though.
26. ◴[] No.45678522[source]
27. Schiphol ◴[] No.45679270{6}[source]
*fora