from Matthias Dillier

The 'magical' shell history: Atuin

Linux, Shell

Shell history

Anyone who works with a shell under Linux will quickly appreciate the history function. Instead of typing commands over and over again, you can use the arrow key to retrieve old commands or repeat commands from the history with «!». The combination history | grep search string is certainly familiar to many.

In this blog post, I present a better and more powerful way of working with the shell history by using the Atuin used.

What is Atuin

On the Website with the documentation Atuin is described as follows:

Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands. With this context, Atuin gives you faster and better search of your shell history.

Additionally, Atuin (optionally) syncs your shell history between all of your machines. Fully end-to-end encrypted, of course.

Atuin is a replacement of the shell history by a database, which offers useful extensions and, if desired, even the synchronisation of the shell history across several systems.

Atuin is open source software and is only supported by sponsors. The developers are happy to receive support.

Supported shells

Atuin supports the following shell variants:

  • zsh
  • bash
  • fish
  • nushell
  • xonsh

Further development

In connection with Atuin, tools are now also being developed with which shell configuration files can be synchronised between computers in order to be able to use environment variables and aliases consistently on different computers. (See: https://docs.atuin.sh/guide/dotfiles/)

Another tool is Atuin Desktop, which aims to bring together documentation and executable programme sequences. (See: https://github.com/atuinsh/desktop)

Installation

There is a script for the installation of Atuin which can be downloaded and executed with the following command:

curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh

For example, the command supplements the configuration file .bashrc for bash with the command

eval "$(atuin init bash)"

to start the Atuin initialisation script when the bash shell is started. The path variable should be added to .bashrc with the atuin command:

PATH="$PATH:~/.atuin/bin"

For the bash shell, it is recommended to also use ble.sh to install.

ble.sh is a bash shell line editor which Syntax highlighting (also with colours), Command completion, one vim edit mode and other features. Atuin can use it for command completion and the coloured display of commands. The current build status of ble.sh can be installed with the following command (all on one line):

curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf -bash ble-nightly/ble.sh --install ~/.local/share

In .bashrc, ble.sh should also be started immediately with the following line before Atuin is started:

source -- ~/.local/share/blesh/ble.sh

Existing command history

After installation, Atuin can import the existing shell command history and then use it in the same way as new commands. The import is done with the following command:

atuin import auto

Here is the documentation of the import command:

$ atuin help import
Import shell history from file

Usage: atuin import 

Commands:
  auto Import history for the current shell
  zsh Import history from the zsh history file
  zsh-hist-db Import history from the zsh history file
  bash Import history from the bash history file
  replxx Import history from the replxx history file
  resh Import history from the resh history file
  fish Import history from the fish history file
  nu Import history from the nu history file
  nu-hist-db Import history from the nu history file
  xonsh Import history from xonsh json files
  xonsh-sqlite Import history from xonsh sqlite db
  help Print this message or the help of the given subcommand(s)

Use and stored data

Atuin can be customised to your own requirements via configuration files. The information here refers to the default configuration after the installation of Atuin in the bash shell.

While using the shell, Atuin saves the following information in the database, which can then be used in Atuin (see: https://docs.atuin.sh/guide/basic-usage/):

  • Command used
  • Directory in which the command was called
  • Time of the command call and the execution time
  • Return value of the command
  • Host and user names
  • Shell session in which the command was called

TUI, Terminal User Interface

Use the up arrow key or the the user interface can be started. Here is a screenshot as an example:

Atuin commands in the shell

The most important shortcuts can also be seen at the top:

  • to leave Atuin
  • to get the command on the command line to customise it there
  • to execute the command directly

Use the up and down arrow keys to navigate through the commands.

With you can change the scope between [GLOBAL] as in the screenshot and [HOST], [SESSION] or [DIRECTORY]. All commands from the history or only those from the same host, those from the current session or those that were called in the current directory are then displayed.

opens the 'Inspector'. The inspector can be used to view the information stored for the current command and also to delete the corresponding entry from the Atuin database.

, where # stands for the number (1 to 9) of the command in the list, calls up the command with this number.

If you simply start typing, a 'fuzzy' search is carried out in the history for the text typed and the commands found are displayed.

Atuin commands in the shell

With you can switch between the different search modes PREFIX, FULLTEXT and FUZZY. PREFIX would not return any results in the example, FULLTEXT would only return the lowest commands where the search text is outlined in red and FUZZY usually helps even if you no longer know the exact command.

Shortcuts

The default shortcuts are stored in the Documentation described as follows:

ShortcutAction
enterExecute selected item
tabSelect item and edit
ctrl + rCycle through filter modes
ctrl + sCycle through search modes
alt + 1 to alt + 9Select item by the number located near it
ctrl + c / ctrl + d / ctrl + g / escReturn original
ctrl + yCopy selected item to clipboard
ctrl + ⬅️ / alt + bMove the cursor to the previous word
ctrl + ➡️ / alt + fMove the cursor to the next word
ctrl + b / ⬅️Move the cursor to the left
ctrl + f / ➡️Move the cursor to the right
ctrl + a / homeMove the cursor to the start of the line
ctrl + e / endMove the cursor to the end of the line
ctrl + backspace / ctrl + alt + backspaceRemove the previous word / remove the word just before the cursor
ctrl + delete / ctrl + alt + deleteRemove the next word or the word just after the cursor
ctrl + wRemove the word before the cursor even if it spans across the word boundaries
ctrl + uClear the current line
ctrl + n / ctrl + j / ⬆️Select the next item on the list
ctrl + p / ctrl + k / ⬇️Select the previous item on the list
ctrl + oOpen the inspector
page downScroll search results one page down
page upScroll search results one page up
⬇️ (with no entry selected)Return original or return query depending on settings
⬇️Select the next item on the list

Search

Atuin offers many search options to find commands in the history. A small example is the following search, which displays the oldest sudo command from the history:

atuin search --limit 1 --reverse sudo

The search in Atuin is on the Website described as follows:

Atuin search supports wildcards, with either the * or % character. By default, a prefix search is performed (ie, all queries are automatically appended with a wildcard).

ArgDescription
-cwd/-cThe directory to list history for (default: all dirs)
-exclude-cwdDo not include commands that ran in this directory (default: none)
-exit/-eFilter by exit code (default: none)
-exclude-exitDo not include commands that exited with this value (default: none)
-beforeOnly include commands ran before this time(default: none)
-afterOnly include commands ran after this time(default: none)
-interactive/-iOpen the interactive search UI (default: false)
-humanUse human-readable formatting for the timestamp and duration (default: false)
-limitLimit the number of results (default: none)
-offsetOffset from the start of the results (default: none)
-deleteDelete history matching this query
-delete-it-allDelete all shell history
-reverseReverse order of search results, oldest first
-format/-fAvailable variables: {command}, {directory}, {duration}, {user}, {host}, {time}, {exit} and {relativetime}. Example: -format “{time} - [{duration}] - {directory}$\t{command}“
-inline-heightSet the maximum number of lines Atuin's interface should take up
-help/-hPrint help

It is interesting to be able to work with --exit or --exclude-exit Past commands with a specific exit code or, for example, those that were not executed successfully
(--exclude-exit 0).

Statistics

With atuin stats you get simple statistics on the commands in the history. With atuin history list the saved commands and data are output, whereby the format of the output can be customised with parameters.

Update

If you have access to the Internet, you can easily perform an update with the following command:

atuin-update

Support

There is a forum for questions about Atuin: https://forum.atuin.sh/

Ideas for further developments can also be suggested in the forum.

Synchronisation between computers

It is possible to save and synchronise the history with Atuin across computer boundaries. To do this, Atuin requires a database on a synchronisation server in the cloud or on your own computer, which is then used from different computers. The data transport from and to the database is securely encrypted.

The details are not covered in this blog post. They are described on the Atuin website: https://docs.atuin.sh/self-hosting/server-setup.

Conclusion

The open source tool Atuin offers an improved and easy-to-use shell history with many search options. It is quick to install and can also be used securely across computer boundaries if required. An all-round successful little tool that makes working with the shell easier.

Photo of author

Matthias Dillier

mathematician, computer scientist and saxophonist with many years of experience in in various areas of computer science. He is currently particularly involved in monitoring, problem analyses, log evaluations, graphics and the automation and the automation of operating processes.

Hinterlassen Sie einen Kommentar

12 − 12 =