Back to TIL
shell

Execute a command without keeping it in Atuin

I really fell into a rabbithole with Atuin. There is one classic bash feature (shortcut) I missed though: sometimes you don’t want certain commands to be saved to shell history (HISTCONTROL).

This is especially useful when running CLI commands with credentials, like API tokens. Bash has this feature whereby simply putting a space at the beginning, a line is not committed to history. Let me demonstrate:

# Logs to history:
$ API_TOKEN="super secret token" dangerous-command
# Does not: (if HISTCONTROL=ignorespace or ignoreboth)
$  API_TOKEN="super secret token" dangerous-command

Reading through the Atuin docs, I stumbled over history_filter. It made me realize I can simulate this classic Bash feature using a regex:

history_filter = [
    # ...
    # Ignore commands that start with *exactly* 1 space
    "^ ([^ ].*)",
]

After opening a new shell, I was able to test it:

Screenshot of a terminal window showing two commands. The first being “echo ‘this is logged’”. It is missing a leading space, hence it should be ignored by Atuin. The second command is “ echo ‘this is not’”. Notable is that the second echo command has a single leading space before it. Because our regex targets exactly this, we should not be able to find our second command in Atuin.

And to confirm that it works, I triggered Atuin:

Screenshot of a terminal window showing Atuin history output.

One can see a bit of my shell history, but the most important thing is the very last command. It is “echo ‘this is logged’”. The second command is nowhere to be found. Hence, confirming that our regex from above works.