Small Programming Tricks

33 points by bugsmith 11 hours ago on lobsters | 13 comments

Picking up on these little nuggets was always one of my favorite things about pair programming.

I'll share one that I don't see get talked about much but I use it daily. fpp

rg pancakes | fpp 

That will parse all the file paths from the output and allow you open one or more in your editor.

I use it all the time with git status to quickly open all the files I'm working on.

It is a Facebook project, so if anyone has alternatives tools I would be open to trying something else.

andyc | 5 hours ago

Kind of similar -- if you use grep -n to add line numbers:

$ grep -n visit_try */*.py | tee _tmp/z
mycpp/control_flow_pass.py:435:    def oils_visit_try_stmt(self, o: 'mypy.nodes.TryStmt') -> None:
mycpp/cppgen_pass.py:2850:    def oils_visit_try_stmt(self, o: 'mypy.nodes.TryStmt') -> None:

Then open _tmp/z in Vim, and hit gF over any line, then it will jump directly to that file and line.

It works with lint tools and compilers too, because they all tend to output this "microformat" of filename:line123

ryan-duve | 51 minutes ago

I have no idea how it works, but many years ago I stumbled upon this:

vim -q <(grep -n visit_try */*.py)

and then use :cn to move from match to match. The help docs call it an "errorfile" but I think of it as my grep navigator.

Nice. I'd love to have something similar that would instead append the selected files as arguments to the command I'm currently constructing.

$ rg pancakes
(...)
$ ./add-maple-syrup [I press a shortcut here and select files from the previous output]

Kind of similar to fpp's command mode but integrated with the shell so I keep other shell features like the history.

lonami | 2 hours ago

I had been using my own similar tool (Python script), but instead it looks at the clipboard for looks-like-a-file. I'm still very much using my mouse, so this way I can visually control what I want to open.

Another benefit is that this works everywhere, even outside the terminal, or after a slow command I can decide if I want to open the output or not without having to run it again with a pipe.

trenchant | 5 hours ago

Is programming more than a massive collection of small tricks? They are fun!

A coherent paradigm with well designed, interworking primitives shouldn't offer many trips, but just synergistic expectable behavior.

you don't need find but that's because you should install fd instead (:

I'm a huge fan of bfs because often the files I look for are shallow in the hierarchy. In such cases breadth-first search is much faster than depth-first search.

danlamanna | 4 hours ago

Obligatory fselect mention. It defaults to breadth-first search too.

nishantjosh | 6 hours ago

I have been using atuin for a long time, I also like using zoxide. with it's zi command

LolPython | 4 hours ago

I didn’t know you could get ** in bash! I’ll have to try that tomorrow. The part on applying log10 to metrics went a bit over my head, but this stats stackoverflow answer helped a lot:

Log-scale informs on relative changes (multiplicative), while linear-scale informs on absolute changes (additive). When do you use each? When you care about relative changes, use the log-scale; when you care about absolute changes, use linear-scale. This is true for distributions, but also for any quantity or changes in quantities.

link

ryan-duve | 43 minutes ago

I used to give mini-workshops on tips like this and the one I saw get the most adoption, lasting many years down the road, was ctrl-r. It searches history for something you've typed at a prompt before. What makes it so powerful is it works across Bash/ZSH, IPython, erl/iex, Claude Code... just anywhere there's a prompt.

It's been very rewarding to see my colleagues go on to teach it to others.