<h1 id="histdb-rs">histdb-rs</h1>
<p><img src="https://github.com/AlexanderThaller/histdb-rs/workflows/Rust/badge.svg?branch=main" alt="Build Status" /> <a href="https://crates.io/crates/histdb-rs"><img src="https://img.shields.io/crates/v/histdb-rs.svg" alt="crates.io" /></a></p>
<p>Better history management for zsh. Based on ideas from <a href="https://github.com/larkery/zsh-histdb">https://github.com/larkery/zsh-histdb</a>.</p>
<p>Licensed under MIT.</p>
<p>It was mainly written because the sqlite merging broke a few to many times for me and using a sqlite database seemed overkill.</p>
<p>The tool is just writing CSV files for each host which makes syncing them via git pretty painless.</p>
<p>Has pretty much the same feature set as zsh-histdb:</p>
<ul>
<li>Start and stop time of the command</li>
<li>Working directory in which the command was run</li>
<li>Hostname of the machine the command was run in</li>
<li>Unique session ids based on UUIDs</li>
<li>Exit status of the command</li>
<li>Import from zsh histfile and zsh-histdb sqlite database</li>
</ul>
<h2 id="installation">Installation</h2>
<p>Currently you need nightly to build histdb-rs. We are using the strip functionality to decrease the binary size automatically.</p>
<pre><code>cargo +nightly install --path .</code></pre>
<p>Or install it from crates.io</p>
<pre><code>cargo +nightly install histdb-rs</code></pre>
<p>After that you need to start the server. This might change in the future.</p>
<pre><code>histdb-rs server</code></pre>
<p>To stop the server you have to run</p>
<pre><code>histdb-rs stop</code></pre>
<p>In the future <code>CTRL+C</code> should also work.</p>
<p>You can also use the systemd unit file in <a href="histdb-rs.service"><code>histdb-rs.service</code></a> which you can copy to <code>"$HOME/.config/systemd</code> and enable/start with the following:</p>
<pre><code>systemctl --user daemon-reload
systemctl --user enable histdb-rs.service
systemctl --user start histdb-rs.service</code></pre>
<p>After that you can add the following to your <code>.zshrc</code> to enable histdb-rs for you shell.</p>
<pre><code>eval "$(histdb-rs init)"</code></pre>
<p>You can run that in your current shell to enable histdb-rs or restart your shell.</p>
<h2 id="usage">Usage</h2>
<p>Help output of default command:</p>
<pre><code>» histdb -h
histdb-rs 0.1.0
USAGE:
histdb-rs [FLAGS] [OPTIONS] [SUBCOMMAND]
FLAGS:
--all-hosts
Print all hosts
--disable-formatting
Disable fancy formatting
-h, --help
Prints help information
--hide-header
Disable printing of header
-i, --in
Only print entries that have been executed in the current directory
--no-subdirs
Exclude subdirectories when filtering by folder
--show-duration
Show how long the command ran
--show-host
Print host column
--show-pwd
Show directory in which the command was run
--show-session
Show session id for command
--show-status
Print returncode of command
-V, --version
Prints version information
OPTIONS:
-c, --command <command>
Only print entries beginning with the given command
-t, --text <command-text>
Only print entries containing the given regex
-d, --data-dir <data-dir>
Path to folder in which to store the history files [default: $HOME/.local/share/histdb-rs]
-e, --entries-count <entries-count>
How many entries to print [default: 25]
-f, --folder <folder>
Only print entries that have been executed in the given directory
--hostname <hostname>
Filter by given hostname
SUBCOMMANDS:
disable
Disable history recording for current session
enable
Enable history recording for current session
help
Prints this message or the help of the given subcommand(s)
import
Import entries from existing histdb sqlite file
init
Print out shell functions needed by histdb and set current session id
precmd
Finish command for current session
running
Tell server to print currently running command
server
Start the server
session_id
Get new session id
stop
Stop the server
zshaddhistory
Add new command for current session</code></pre>
<p>The most basic command ist just running <code>histdb-rs</code> without any arguments:</p>
<pre><code>» histdb-rs
tmn cmd
14:28 cargo +nightly install --path .</code></pre>
<p>That will print the history for the current machine. By default only the last 25 entries will be printed.</p>
<h2 id="git">Git</h2>
<p>Histdb-rs was written to easily sync the history between multiple machines. For that histdb-rs will write separate history files for each machine.</p>
<p>If you want to sync between machines go to the datadir (default is <code>$HOME/.local/share/histdb-rs</code>) and run the following commands:</p>
<pre><code>git init
git add :/
git commit -m "Initial commit"</code></pre>
<p>After that you can configure origins and start syncing the files between machines. There is no autocommit/autosync implemented as we don’t want to have commits for each command run. This could be changed in the future.</p>
<h2 id="import">Import</h2>
<h3 id="zsh-histdb">zsh-histdb</h3>
<pre><code>» histdb import histdb -h
histdb-rs-import-histdb 0.1.0
Import entries from existing histdb sqlite file
USAGE:
histdb-rs import histdb [OPTIONS]
FLAGS:
-h, --help
Prints help information
OPTIONS:
-d, --data-dir <data-dir>
Path to folder in which to store the history files [default: $HOME/.local/share/histdb-rs]
-i, --import-file <import-file>
Path to the existing histdb sqlite file [default: $HOME/.histdb/zsh-history.db]</code></pre>
<p>If the defaults for the <code>data-dir</code> and the <code>import-file</code> are fine you can just run the following command:</p>
<pre><code>histdb import histdb</code></pre>
<p>This will create CSV files for each <code>hostname</code> found in the sqlite database. It will create a UUID for each unique session found in sqlite so command run in the same session should still be grouped together.</p>
<h3 id="zsh-histfile">zsh histfile</h3>
<pre><code>» histdb import histfile -h
histdb-rs-import-histfile 0.1.0
Import entries from existing zsh histfile
USAGE:
histdb-rs import histfile [OPTIONS]
FLAGS:
-h, --help
Prints help information
OPTIONS:
-d, --data-dir <data-dir>
Path to folder in which to store the history files [default: $HOME/.local/share/histdb-rs]
-i, --import-file <import-file>
Path to the existing zsh histfile file [default: $HOME/.histfile]</code></pre>
<p>If the defaults for the <code>data-dir</code> and the <code>import-file</code> are fine you can just run the following command:</p>
<pre><code>histdb import histfile</code></pre>
<p>As the information stored in the histfile is pretty limited the following information will be stored:</p>
<ul>
<li><code>time_finished</code> will be parsed from the histfile</li>
<li><code>result</code> (exit code) will be parsed from the histfile</li>
<li><code>command</code> will be parse from the histfile</li>
<li><code>time_start</code> will be copied over from <code>time_finished</code></li>
<li><code>hostname</code> will use the current machines hostname</li>
<li><code>pwd</code> will be set to the current users home directory</li>
<li><code>session_id</code> will be generated and used for all commands imported from the histfile</li>
<li><code>user</code> will use the current user thats running the import</li>
</ul>