いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

Atuin (Magical Shell History, シェルの履歴管理を便利にしてくれる)

関連記事

GitHub - devlights/blog-summary: ブログ「いろいろ備忘録日記」のまとめ

概要

以下、自分用のメモです。忘れないうちにメモメモ。。。

AtuinというCLIツールの存在を知りました。シェルの履歴管理を便利にしてくれるCLIツール。

atuin.sh

github.com

名前を知ったのは以下のGitpodさんのブログ記事でした。

www.gitpod.io

とても良い感じですねー。historyを探すのが楽になるのと、目玉機能のもう一つはコマンドの履歴をサーバーで保存しておいて複数端末で同期することが出来るという点みたい。

同期する・しないはオプショナルで選べるとのこと。

試してみる

Linux+bash環境はでやりました。私はサーバーにコマンド履歴を同期するオプションは必要無いので有効化せずに進めています。複数端末とコマンド履歴を同期させる場合のやり方は参考情報のところでリンク貼っているサイト様の記事がとてもわかりやすく説明されていますので、そちらをご参照ください。

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy



$ curl https://setup.atuin.sh | less



$ bash <(curl https://setup.atuin.sh)
 _______  _______  __   __  ___   __    _
|   _   ||       ||  | |  ||   | |  |  | |
|  |_|  ||_     _||  | |  ||   | |   |_| |
|       |  |   |  |  |_|  ||   | |       |
|       |  |   |  |       ||   | |  _    |
|   _   |  |   |  |       ||   | | | |   |
|__| |__|  |___|  |_______||___| |_|  |__|

Magical shell history

Atuin setup
https://github.com/atuinsh/atuin

Please file an issue if you encounter any problems!

===============================================================================

Detected Linux!
Checking distro...
Ubuntu detected


[割愛]


 _______  __   __  _______  __    _  ___   _    __   __  _______  __   __
|       ||  | |  ||   _   ||  |  | ||   | | |  |  | |  ||       ||  | |  |
|_     _||  |_|  ||  |_|  ||   |_| ||   |_| |  |  |_|  ||   _   ||  | |  |
  |   |  |       ||       ||       ||      _|  |       ||  | |  ||  |_|  |
  |   |  |       ||       ||  _    ||     |_   |_     _||  |_|  ||       |
  |   |  |   _   ||   _   || | |   ||    _  |    |   |  |       ||       |
  |___|  |__| |__||__| |__||_|  |__||___| |_|    |___|  |_______||_______|



Thanks for installing Atuin! I really hope you like it.

If you have any issues, please open an issue on GitHub or visit our Discord (https://discord.gg/dPhv2B3x)!

If you love Atuin, please give us a star on GitHub! It really helps ⭐️ https://github.com/atuinsh/atuin

Please run "atuin register" to get setup with sync, or "atuin login" if you already have an account

インストールが完了すると、.bashrcatuin の呼び出しが追加されてます。

$ tail -n 2 .bashrc
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh
eval "$(atuin init bash)"

.bash-preexec.sh は、zsh の preexec , precmd 関数の機能をbashでサポートさせるためのスクリプトみたい。

$ head .bash-preexec.sh
# bash-preexec.sh -- Bash support for ZSH-like 'preexec' and 'precmd' functions.
# https://github.com/rcaloras/bash-preexec
#
#
# 'preexec' functions are executed before each interactive command is
# executed, with the interactive command as its argument. The 'precmd'
# function is executed before each prompt is displayed.
#
# Author: Ryan Caloras (ryan@bashhub.com)
# Forked from Original Author: Glyph Lefkowitz

後は、シェルを再起動したら有効になります。

$ source .bashrc

history関連の操作(上矢印、Ctrl-r) を押すと以下のように表示されるようになります。

絞り込みなどがとてもやりやすいので良いですね。

参考情報

remoteroom.jp


過去の記事については、以下のページからご参照下さい。

サンプルコードは、以下の場所で公開しています。