Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

271–280 of 408 posts

Re: Scripts I wrote that I use all the time

#271

While you're creating and testing aliases, it's handy to source your ~/.zshrc whenever you edit it: alias vz="vim ~/.zshrc && . ~/.zshrc" I alias mdfind to grep my .docx files on my Mac: docgrep() { mdfind "\"$@\"" -onlyin /Users/xxxx/Notes 2> >(grep --invert-match ' \[UserQueryParser\] ' >&2) | grep -v -e '/Inactive/' | sort } I use an `anon` function to anonymize my Mac clipboard when I want to paste something to t…

What's the difference between 'source' and '.' ?

Re: Scripts I wrote that I use all the time

#272
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…

This is terrific! I curl to files and then pipe them, all the time. This will be a great help.

I wonder if we have gotten to the point where we can feed an LLM our bash history and it could suggest improvements to our workflow.

Re: Scripts I wrote that I use all the time

#273

The most useful script I wrote is one I call `posh`. It shorten a file path by using environment variables. Example: $ posh /home/ramrachum/Dropbox/notes.txt $DX/notes.txt Of course, it only becomes useful when you define a bunch of environment variables for the paths that you use often. I use this a lot in all of my scripts. Basically whenever any of my script prints a path, it passes it through `posh`.

I'd love to see this script. Does it use `env` and strip out things like PWD?

I wrote it in a way that's too intertwined with my other shit to be shareable with people, but honestly you can copy-paste my comment to your friendly neighborhood LLM and you'll get something decent. Indeed it uses `env`.

Re: Scripts I wrote that I use all the time

#274
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…

15 years of Linux and I learn something new all the time...

Its why I keep coming back, now how do I remember to use this and not go back to using tmpfiles :)

Re: Scripts I wrote that I use all the time

#275
post #262

I've written on this before, but I have an extensive collection of "at" scripts. This started 25+ years ago when I dragged a PC tower running BSD to a friend's house, and their network differed from mine. So I wrote an @friend script which did a bunch of ifconfig foo. Over time that's grown to an @foo script for every project I work on, every place I frequent that has some kind of specific setup. They are prefixed wi…

I'm stealing the top comment here because you probably know what I'm asking.

I've always wanted a linux directory hook that runs some action. Say I have a scripts dir filled with 10 different shells scripts. I could easily have a readme or something to remember what they all do.

What I want is some hook in a dir that every time I cd into that dir it runs the hook. Most of the time it would be a simple 'cat usage.txt' but sometimes it maybe 'source .venv/bin/activate'.

I know I can alias the the cd and the hook together but I don't want that.

Re: Scripts I wrote that I use all the time

#276
post #146

Earlier quoted context omitted.

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.

Or more abstractly: post anything to the internet and people will always detail how you’re wrong. Sometimes that can be useful.

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

#277
post #262

I've written on this before, but I have an extensive collection of "at" scripts. This started 25+ years ago when I dragged a PC tower running BSD to a friend's house, and their network differed from mine. So I wrote an @friend script which did a bunch of ifconfig foo. Over time that's grown to an @foo script for every project I work on, every place I frequent that has some kind of specific setup. They are prefixed wi…

I'm stealing the top comment here because you probably know what I'm asking. I've always wanted a linux directory hook that runs some action. Say I have a scripts dir filled with 10 different shells scripts. I could easily have a readme or something to remember what they all do. What I want is some hook in a dir that every time I cd into that dir it runs the hook. Most of the time it would be a simple 'cat usage.txt'…

direnv does exactly what you describe (and a lot more) using flake.nix. cd into the directory and it automatically runs. I use it in every single project/repository to set environment variables and install project-specific dependencies locked to specific versions.

Re: Scripts I wrote that I use all the time

#278

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.

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

#279

Earlier quoted context omitted.

I'd love to see this script. Does it use `env` and strip out things like PWD?

I wrote it in a way that's too intertwined with my other shit to be shareable with people, but honestly you can copy-paste my comment to your friendly neighborhood LLM and you'll get something decent. Indeed it uses `env`.

Understood. I'd rather write it myself from scratch than use an LLM; confirmation of the general process should be enough, I hope!

Re: Scripts I wrote that I use all the time

#280
post #262

I've written on this before, but I have an extensive collection of "at" scripts. This started 25+ years ago when I dragged a PC tower running BSD to a friend's house, and their network differed from mine. So I wrote an @friend script which did a bunch of ifconfig foo. Over time that's grown to an @foo script for every project I work on, every place I frequent that has some kind of specific setup. They are prefixed wi…

I'm stealing the top comment here because you probably know what I'm asking. I've always wanted a linux directory hook that runs some action. Say I have a scripts dir filled with 10 different shells scripts. I could easily have a readme or something to remember what they all do. What I want is some hook in a dir that every time I cd into that dir it runs the hook. Most of the time it would be a simple 'cat usage.txt'…

I recommend direnv for that: https://direnv.net/

Its intended use case is loading environment variables (you could use this to load your virtualenv), but it works by sourcing a script — and that script can be ‘cat usage.txt.’

Great tool.

If you use Emacs (and you should!), there’s a direnv mode. Emacs also has its own way to set configuration items within a directory (directory-local variables), and is smart enough to support two files, so that there can be one file checked into source control for all members of a project and another ignored for one’s personal config.

Post reply on HN