Hacker News new | ask | show | jobs
by jakebasile 444 days ago
I use Atuin, but unlike the author actually find it more valuable since I use it across many machines. I have 7 different machines (of various make and OS though all *NIX) in my house right now that I regularly SSH in to or use directly, and Atuin's sync keeps my history on all of them. If I want to narrow down by host I can still do that. I also keep similar directory structures so I can narrow down by directory even if I performed a command on a different machine most of the time.

That said, some form of advanced history search is a game changer, no matter how you get it. It's one of those "can't understand how I lived without it" things once you get it going.

3 comments

I’ve started using Atuin based on a recommendation from here a few weeks ago. I generally like it, but feel like the fuzzy matching is bad - maybe I either misconfigured something or nobody else cares about it?

If the command I want to match against is within the last few days or so, the fuzzy match performs ok, but anything from months ago which I know for a fact is in the history, it just doesn’t match it and instead shows irrelevant items (which technically I’m sure according to some algorithm are correct). Another one is I often have to put a ^ to ensure the ‘curl’ I’m searching for starts looking for matches at beginning of line.

Often times I still fall back to using fzf on ~/.zsh_history which seems to get what I want. There is this thread which is same issues I’m seeing, and I did try smart_sort=True but it’s still not great.

https://forum.atuin.sh/t/understanding-atuin-history-search/...

Try to add ' in front of words to find exact matches if the fuzzy search isn't providing the results you're looking for.
If using Nix, you can get Atuin working basically for free by just enabling it in the config. I love it. Does everything I'd every hoped for with history search.
I don't really like nix (yeah I tried it for a couple of months), but I'd like to point out that atuin is exceptionally easy to set up even without using nix as well in case someone gets an idea that it is difficult.
I'm also in this boat. I have atuin as part of my zsh config that is distributed to all new machines, whether they run NixOS or some other operating system with Nix on them (e.g. MacOS). After switching to NixOS I found an interest in maintaining a custom setup again, since it wouldn't fall apart every time I moved machine.

  { pkgs, ... }:
  {

    users.defaultUserShell = pkgs.zsh;

    environment.systemPackages = with pkgs; [
      atuin  # ^R
      eza    # ls
      git
      zsh
    ];

    programs.direnv.enable = true;
    programs.nix-direnv.enable = true;

    programs.zsh = {
      enable = true;
      enableCompletion = true;
      enableBashCompletion = true;
      enableGlobalCompInit = true;

      # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
      syntaxHighlighting.enable = true;
      syntaxHighlighting.highlighters = [ "main" "brackets" ];

      # See `man zshoptions` for more details.
      setOptions = [
        # Remove duplicates continuously from command history (preserve newest entry).
        "HIST_IGNORE_DUPS"

        # Instantly share command history between all active shells.
        "SHARE_HISTORY" # Alternative to: "APPEND_HISTORY", "INC_APPEND_HISTORY",

        # Disable ^S and ^Z for less accidental freezing.
        "FLOW_CONTROL"

        # Save timestamp and duration of each command in command history.
        "EXTENDED_HISTORY"
      ];

      shellAliases = {
        # Navigation
        rm = "rm -iv";
        ls = "eza -lg";
        tree = "eza -lgT";

        # git aliases
        # ...
      };

      promptInit = ''
        autoload -U promptinit
        promptinit
        prompt off

        # Simple:
        # PS1='[%n@%m:%~] %(!.#.$) '

        # Colorful:
        # PS1='[%F{green}%n@%m%f:%F{blue}%~%f] %(!.#.$) '

        # Colorful with git branch:
        function git_branch_name() {
          branch=$(git symbolic-ref HEAD --short 2>/dev/null)
          if [ ! -z "$branch" ]; then
            echo -n " [%F{red}$branch%f]"
          fi
        }

        # Omit username, print hostname + '$' with red when root, otherwise green:
        prompt='[%(!.%F{red}.%F{green})%m%f:%F{blue}%~%f]$(git_branch_name) %(!.%F{red}#%f.$) '

        # See: https://zsh.sourceforge.io/Doc/Release/Options.html#Prompting
        setopt prompt_cr
        setopt prompt_sp
        setopt prompt_subst

        export PROMPT_EOL_MARK=""
      '';

  interactiveShellInit = ''
        # Prevent user-level "config missing" message.
        touch $HOME/.zshrc

        # MacOS
        bindkey '^[[7~' beginning-of-line
        bindkey '^[[8~' end-of-line

        # Linux
        bindkey '^[[1;3D' beginning-of-line  # alt+left
        bindkey '^[[1;3C' end-of-line        # alt+right
        bindkey '^[[1;5D' backward-word      # ctrl+left
        bindkey '^[[1;5C' forward-word       # ctrl+right

        # Both
        bindkey '^R' history-incremental-search-backward
        bindkey '^U' kill-whole-line
        bindkey '^Y' yank

        # My SSH endpoints don't recognize modern terminals

        export TERM=xterm-256color

        # ^R only
        eval "$(atuin init zsh --disable-up-arrow)"
      '';
    };
  }
Or if using home manager:

        programs.atuin = {
          enable = true;
          enableZshIntegration = true;
        };
Did you really need to share 108 lines of code, inline, rather than a link to gist/similar?

The chances of people reading this discussion running NixOS are small, and of those I'm sure the ones who were interested could search the internet for examples.

NixOS and Kagi user here. Hacker News often is the most reliable search result there is. Gists aren’t (they become easily deleted, unlike HN comments).
Sure, and I accept that happily enough for "small" snippets. But I had to page down multiple times and it really felt like too much content.
I could have cut down the sample a lot, I apologize.
Curious on this: "Atuin's sync keeps my history on all of them"

I just checked on their GitHub and it says "Additionally, it provides optional and fully encrypted synchronisation of your history between machines, via an Atuin server."

So you trust all of your shell commands to be stored on a server that you don't control?

Maybe I'm missing something here.

Sync is optional*, end to end encrypted, and you can self host the server so you don't really need to trust anything if you don't want to

*: nothing syncs if you don't register, and you can even compile a version with the sync code flagged out if you REALLY don't want to trust anything

Got it, thx!