Skip to main content

Logs bash history to an sqlite database

Project description

Recent

Recent is a more structured way to log your bash history.

The standard ~/.bash_history file is inadequate in many ways, its worst fault is to by default log only 500 history entries, with no timestamp. You can alter your bash HISTFILESIZE and HISTTIMEFORMAT variables but it is still a unstructured format with limited querying ability.

Recent does the following.

  1. Logs current localtime, command text, current pid, command return value, working directory to an sqlite database in ~/.recent.db.
  2. Logs history immediately, rather than at the close of the session.
  3. Provides a command called recent for searching bash history.

NOTE about trengrj/recent

recent2 is a clone of trengrj/recent. I used trengrj's util for about a month and I really liked it. However I saw some short comings in the tool. I made a clone because trengrj has not been very responsive.

Most of the code is written by trengrj. I only added a few incremental patches; but I intend to actively maintain this as I see more interesting use cases.

Installation instructions

You need will need sqlite installed.

Install the recent pip package.

pip install recent2

Add the following to your .bashrc or .bash_profile.

export PROMPT_COMMAND='log-recent -r $? -c "$(HISTTIMEFORMAT= history 1)" -p $$'

And start a new shell.

Usage

See example usage at https://asciinema.org/a/271533

Look at your current history using recent. Here are some examples on how to use recent.

# Help
recent -h
# Look for all git commands
recent git
# Look for git commit commands.
# Query via regexp mode.
recent -re git.*commit
# Look for git commands that are not commits.
# Query via sql mode.
recent -sql 'command like "%git%" and command not like "%commit%"'

By default recent commands are not displayed in the output. To see the recent commands pass the return_self argument as follows.

recent git --return_self

For more information run recent -h

You can directly query your history running sqlite3 ~/.recent.db "select * from commands limit 10"

Dev installation instructions

git clone https://github.com/dotslash/recent2 && cd recent2
pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

recent2-0.1.7.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

recent2-0.1.7-py2.py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page