Directory based history is a tool to maintain a database of command line events in a filterable manner.
Storing bash history per directory can be useful if a developer works on several projects in parallel. In this case, build, test, lint commands can vary. When only bash history is used, the developer needs to grep for the used commands or look up the script or config files, like package.json. By using dbhistory, this process can be simplified by simply running dbhistory in the workspace of the project and it'll dump the commands executed on that project.
On Ubuntu or any ubuntu based distros it can be installed by using ppa https://launchpad.net/~vargab95/+archive/ubuntu/dbhistory
mkdir build
cd build
cmake ..
make
sudo make install
Add to the end of .bashrc.
export PROMPT_COMMAND='RETRN_VAL=$?;dbhistory -a "$(history | tail -n1 | sed "s/^[ ]*[0-9]*[ ]*//" )"'
The configuration file shall be in INI format. The path of the configuration file can be specified (see in the Command line arguments section). By default, the configuration file path is $HOME/.dbhistory.ini
Specifies the path where the SQLite database will be stored.
Default value is $HOME/.dbhistory.db
Specifies the path where the logs will be stored.
Default value is $HOME/.dbhistory.log
Time threshold for deleting old history records. The unit is second.
The default value is -1 which means, there is no time threshold for all entries.
Specifies the maximum length of a command which can be stored.
Default is 4096.
Specifies whether the pinnings feature is enabled.
Default is 1.
Specifies the log level to be used.
The following values can be used:
- 0 = TRACE
- 1 = DEBUG
- 2 = INFO
- 3 = WARNING
- 4 = ERROR
The default value is INFO (2).
Specifies the default limit of result records. Only the last n records will be printed by dbhistory to avoid slow listing due to printing thousands of commands. Can be overriden by the -l command line argument.
The default value is 100.
- -h Shows this help message
- -f Specify configuration file
- -c Cleans up the database
- -a Adds the COMMAND to the history db
- -s Search by applying given regex to pathes
- -p Pin a command to the current folder
- -u Unpin a command by ID
- -o Show only the history without pinnings
- -l Limit the number of results
As dbhistory uses SQLite3 by default, it does not make sense to write predefined statistic commands into the tool. If you're interested in history statistics, it's recommended to open the database file with an sqlite browser and create views for the statistics. For example, a history count per path statistics view can be created by executing the following SQL statement.
CREATE VIEW history_count_per_path
AS
SELECT path, COUNT(history.path_id) AS occurence
FROM history JOIN path_map ON path_map.id == history.path_id
GROUP BY history.path_id
ORDER BY occurence DESC