alt.hn

3/25/2025 at 12:02:45 PM

Better Shell History Search

https://tratt.net/laurie/blog/2025/better_shell_history_search.html

by todsacerdoti

3/28/2025 at 7:01:40 AM

I use bog-standard zsh without any plugins or any of the fancy stuff, but one of the most useful tricks I use is to leverage interactive comments. If I have a long command I know I run will frequently, I 'tag' them at the end by a shell comment[1].

So for example, I have one that I use to run software updates:

    softwareupdate --include-config-data --install --all --restart # system:update:restart
I have a similar one without the `--restart` option that I tag with `:norestart` instead, but you get the idea—I put related commands under a common term.

Then I can just use the ctrl-r builtin keybinding, type `:system` and cycle through system related commands, or go exactly to the command I want. The beauty of this is that it also works in bash and systems I remote into (which I frequently need to do at work), without any extra plugins required.

[1]: interactive comments are disabled by default in zsh, but can be enabled with `setopt interactive_comments`

by ackyshake

3/28/2025 at 9:12:06 AM

Interesting approach. Im so lazy I would just create a alias with the commands initials so "sur" but I guess that can get confusing if there are too many.

by akimbostrawman

3/29/2025 at 12:42:34 AM

For sure. Personally, I avoid shortened aliases like that. I regularly need to use barebones systems so I wouldn't like something like "ll" (`ls -l`) or "gst" (`git status`) becoming muscle memory. Most of my aliases I do define are proper english words.

by ackyshake

3/28/2025 at 12:18:49 AM

I use Atuin and like it a lot, and sync history across hosts.

However, the fuzzy search in Atuin is worse than fzf, which was a downgrade. It just has less effective heuristics/scoring, e.g. it might find the individual letters of a short command scattered in a command that had a long base64 input or something.

by BeeOnRope

3/28/2025 at 5:02:53 AM

You can use ' to do exact match, like 'docker

https://docs.atuin.sh/configuration/config/#fuzzy-search-syn...

by bayesianbot

4/3/2025 at 1:56:21 AM

Yes, I rely heavily on ^ and ' in antuin, though that's partly to workaround the relatively poor fuzzy search (in fzf I never even needed those).

by BeeOnRope

3/28/2025 at 4:08:46 AM

it's worth noting that atuin is now available in debian testing/trixie, so it will eventually be an apt install away for new stable installs.

by khimaros

3/27/2025 at 11:46:09 PM

I have my own solution that I've been using for many years — I record all my bash history.

Bash has a hook (cannot remember the name on my phone) that is called on every command.

It's easy enough to write into a file the command together with the directory and git branch.

Then I can grep it with a bash function that colors the dir and branch in the output.

It does not replace ctrl-r but it's a great addition especially when running multiple sessions and bash saving just the last one

by yb303

3/28/2025 at 8:52:09 AM

> Bash has a hook (cannot remember the name on my phone) that is called on every command.

trap 'echo "$BASH_COMMAND" >> ~/.bash_history_extra' DEBUG

this runs before commands, not after the whole command line (before prompt is displayed).

my personal bash history tweak suit is based on this. with a load of complexity of course, because the DEBUG trap is also triggered before each PROMPT_COMMAND commands and on every simple command within the issued command line. so the above example would record each command of a pipeline separately.

by bandie91

3/27/2025 at 11:46:09 PM

Dupe of https://news.ycombinator.com/item?id=43476793

Decades have passed and HN still can’t automatically dedup submissions.

by 7e

3/28/2025 at 12:07:12 AM

Usually it does de-dupe any submission with "significant attention", but I'm not sure what the threshold for that is.

I'd think the submissions from two days ago (206 points, 93 comments) would have qualified. (It's the exact same URL so that's not why it wasn't de-duped either.)

https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...

by js2

3/28/2025 at 1:29:44 AM

Pretty sure dedupe is done manually by u/dang.

by joatmon-snoo

3/28/2025 at 2:31:23 AM

Yes, he can manually merge duplicate submissions and their comments.

But there's times when I've submitted items that are dupes and it just takes me to the recent submission and adds an upvote. Now here's something weird: I just tested this by submitting the URL from this submission with the same title and it immediately took me to the discussion from two days ago.

So I'm really confused how this dupe got through.

by js2

3/27/2025 at 11:50:10 PM

Why dedup? Old forgotten things are as good as new :)

by yb303

3/28/2025 at 6:52:50 AM

2 years might be OK, but not 2 days as in this case.

by usr1106

3/28/2025 at 1:32:08 AM

I'm ok with dupes. But cross-linking should at least be automatic.

by montag

3/28/2025 at 3:26:28 AM

i use the open source Glider frontend on Android and it shows related posts automatically. recommended.

by khimaros

3/27/2025 at 11:50:31 PM

Isn't this intentional? How would deduping work?

by efilife

3/28/2025 at 12:20:13 AM

Have been using Atuin for a couple (few?) years, it's great! How many others are using it too? I'm curious what everyone's tool of choice for shell search is!

https://github.com/atuinsh/atuin

by kyyol

3/28/2025 at 3:24:40 AM

happy user here. atuin coupled with z has made it so much easier to be productive across multiple projects (especially less frequently accessed ones). just "z project" and then Ctrl+r twice to see the most recently used commands in that directory.

by khimaros

3/28/2025 at 3:14:00 AM

I’ve always just done

  alias hst=“history | fzf”
Not nearly as feature full but the simplicity of it makes me happy :)

by doawoo

3/28/2025 at 1:32:04 AM

An unfortunate problem with using awk: there are three different versions of awk, and it is frighteningly easy to use a feature that exists on one but not other.

(source: I have written unit tests against different versions of awk. That was... unpleasant.)

by joatmon-snoo

3/25/2025 at 1:16:19 PM

Aka using fzf/skim with a script for relative timestamps; and some reasons to avoid atuin or fish.

Good to know about skim as an fzf alternative.

by wonger_