Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

311–320 of 408 posts

Re: Scripts I wrote that I use all the time

#311
post #96

Why dont we have mkcd in linux natively boggles my mind :)

Likewise, why doesn't git clone automatically cd into the repo?

A subprocess (git) can't modify the working directory of the parent process (the shell). This is a common annoyance with file managers like yazi and ranger as well—you need an extra (usually manual!) installation step to add a shell integration for whichever shell you're using so the shell itself can change directory.

The best solution for automatically cd'ing into the repo is to wrap git clone in a shell function or alias. Unfortunately I don't think there's any way to make git clone print the path a repository was cloned to, so I had to do some hacky string processing that tries to handle the most common usage (ignore the "gh:" in the URL regex, my git config just expands it to "git@github.com:"):

https://github.com/Andriamanitra/dotfiles/blob/d1aecb8c37f09...

Re: Scripts I wrote that I use all the time

#312
post #250

I have a bunch, but one that I rarely see mentioned but use all the time is memo(1) ( https://github.com/aktau/dotfiles/blob/master/bin/memo ). It memoizes the command passed to it. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' Manually clearing it (for example if I know the underlying data has changed: $ memo -c curl https://some-expensive.com/api/call In-pipeline memoization (includes the input…

Caching some API call because it is expensive and use cached data many months later because of bash suggestion :(

The default storage location for memo(1) output is /tmp/memo/${USER}. Most distributions either have some automatic periodic cleanup, and/or wipe it on restart.

Separately from that:

  - The invocation contains *memo* right in there, so you (the user) knows that it might memoize.
  - One uses memo(1) for commands that are generally slow. Rerunning your command that has a slow part and having it return in a millisecond while you weren't expecting it should make the spider-sense tingle.
In practice, this has never been a problem for me, and I've used this hacked together command for years.

Re: Scripts I wrote that I use all the time

#313
post #250

I have a bunch, but one that I rarely see mentioned but use all the time is memo(1) ( https://github.com/aktau/dotfiles/blob/master/bin/memo ). It memoizes the command passed to it. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' Manually clearing it (for example if I know the underlying data has changed: $ memo -c curl https://some-expensive.com/api/call In-pipeline memoization (includes the input…

Dude, this is _awesome_. Thank you for sharing!

Glad you like it. Hope you get as much use of it as me.

Re: Scripts I wrote that I use all the time

#315

Earlier quoted context omitted.

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

Yes, flagging mechanism on HN is evil.

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

#316
post #250

I have a bunch, but one that I rarely see mentioned but use all the time is memo(1) ( https://github.com/aktau/dotfiles/blob/master/bin/memo ). It memoizes the command passed to it. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' Manually clearing it (for example if I know the underlying data has changed: $ memo -c curl https://some-expensive.com/api/call In-pipeline memoization (includes the input…

You're gonna absolutely love up (https://github.com/akavel/up).

If you pipe curl's output to it, you'll get a live playground where you can finesse the rest of your pipeline.

  $ curl https://some-expensive.com/api/call | up

Re: Scripts I wrote that I use all the time

#317

Earlier quoted context omitted.

This doesn't make sense. You said you were already using someone else's environment. You can't later say that you don't. Whether or not shell access makes sense depends on what you are doing, but a well written application server running in a cloud environment doesn't need any remote shell account. It's just that approximately zero typical monolithic web applications meet that level of quality and given that 90% of "…

They do get to work on someone else's server, they do not get a separate account on that server. There client would be not happy to have them mess around with the environment.

By definition, it the client Alice gives contractor Mallory access to user account alice, that's worse than giving them an account called mallory.

Accounts are basically free. Not having accounts; that's expensive.

Re: Scripts I wrote that I use all the time

#318
post #246

Earlier quoted context omitted.

[flagged]

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 you…

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

#319
post #253

Earlier quoted context omitted.

but alt-. in bash is used for pasting the last argument to the previous command into the current one.

Good point, when working with keybindings, you'll inevitably end up overriding built-ins. I see it as a trade-off, between something I don't know of (and wouldn't use) and something I find useful. Works for me :)

absolutely. From back in the day, the annoying one was GNU screen, which took over ctrl-a by default. Overrode that to be ctrl-^, which in bash is transpose, make "zx be "xz", which was rare enough to okay with losing.

Re: Scripts I wrote that I use all the time

#320
post #250

I have a bunch, but one that I rarely see mentioned but use all the time is memo(1) ( https://github.com/aktau/dotfiles/blob/master/bin/memo ). It memoizes the command passed to it. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' Manually clearing it (for example if I know the underlying data has changed: $ memo -c curl https://some-expensive.com/api/call In-pipeline memoization (includes the input…

You're gonna absolutely love up ( https://github.com/akavel/up ). If you pipe curl's output to it, you'll get a live playground where you can finesse the rest of your pipeline. $ curl https://some-expensive.com/api/call | up

up(1) looks really cool, I think I'll add it to my toolbox.

It looks like up(1) and memo(1) have similar use cases (or goals). I'll give it a try to see if I can appreciate its ergonomics. I suspect memo(1) will remain my mainstay:

  1. After executing a pipeline, I like to press the up arrow (heh) and edit. Surprisingly often I need to edit something that's *not* the last part, but somewhere in the middle. I find this cumbersome in default line editing mode, so I will often drop into my editor (^X^E) to edit the command.
  2. Up seems to create a shell command after completion. Avoiding the creation of extra files was one of my goals for memo(1). I'm sure some smart zsh/bash integration could be made that just returns the completed command after completing.
Post reply on HN