Skip to main content

History logger for xonsh

Project description

Forks Stargazers Issues MIT License LinkedIn

xontrib log_all_history

xonsh history logger

log_all_history persists all shell history in $HOME/.logs while also supporting both the JsonHistory and SqliteHistory backends.

Install

Install using pip

pip install xontrib-log_all_history

Add to your .xonshrc as follows:

xontrib load log_all_history

:warning: If you using SqliteHistory backend, you must include $XONSH_HISTORY_BACKEND = 'sqlite' before loading. For example:

$XONSH_HISTORY_BACKEND = 'sqlite'
xontrib load 'log-all-history'

Architecture

This plugin intercepts history before sending to the JsonHistory or SqliteHistory backend. In short:

  • Take the current command line and append to a history named: $HOME/.logs/$PWD/xonsh-history-{DateTime}.log
  • For example:
 ~/P/P/x/xontrib-log-all-history  cat README.md > /dev/null
 ~/P/P/x/xontrib-log-all-history  tail $LOG_ALL_HISTORY_FILE
2022-03-11.21.17.01 cat README.md > /dev/null
 ~/P/P/x/xontrib-log-all-history 

I've been using this method since October in 2019 (both in bash and now xonsh). Here's stats on my logs directory:

 ~/P/P/x/xontrib-log-all-history  du -sh ~/.logs
16M     /home/mcrowe/.logs
 ~/P/P/x/xontrib-log-all-history  egrep '^201' ~/.logs -Rh | cut -b -7 | sort | uniq | head -n 1
2019-10
 ~/P/P/x/xontrib-log-all-history  find ~/.logs | wc -l
3645
 ~/P/P/x/xontrib-log-all-history 

Searching History

Two helper aliases are enabled to assist in searching your accumulated history:

hgrep -- "H"istory "Grep"

This command is simply grep -ERh {SEARCH_STRING} $HOME/.logs -- it searches all folders.

hgrep -- "H"istory in this "D"irectory "Grep"

This command is simply grep -ERh {SEARCH_STRING} $HOME/.logs/$PWD -- it searches all logs you've done in this specific directory. The use-case for this is:

  • You use the python command frequently
  • You remember using a python command in the past for the current project with a lot of parameters you figured out, but you didn't save it.
    • If you did hgrep python, you'd find many entries.
    • By using hdgrep python, you find the specific command.

Example:

 ~/P/P/x/xontrib-log-all-history  hgrep cat | wc -l
1427
 ~/P/P/x/xontrib-log-all-history  hdgrep cat | wc -l
10
 ~/P/P/x/xontrib-log-all-history 

(yes, I did several cats testing for the readme...)

Optional Configuration

If you want to place to the logs in a different folder, set:

$LOG_ALL_HISTORY_DIR = f"{$HOME}/.all-logs"
xontrib load 'log-all-history'

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

xontrib-log_all_history-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

xontrib_log_all_history-1.0.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file xontrib-log_all_history-1.0.0.tar.gz.

File metadata

  • Download URL: xontrib-log_all_history-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.2.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.8

File hashes

Hashes for xontrib-log_all_history-1.0.0.tar.gz
Algorithm Hash digest
SHA256 31f9b3f3c189fc8f175e273a66b1daac170b0649484327cdbf137afe505c56db
MD5 16583d93e7b8c8d4922f65ff6930b8c4
BLAKE2b-256 49853035467fa3e15ac48baf4480a6ebc6a8930f683bc76e13bd868415762990

See more details on using hashes here.

File details

Details for the file xontrib_log_all_history-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: xontrib_log_all_history-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.2.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.8

File hashes

Hashes for xontrib_log_all_history-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5beb64e4518df979f7171c417da042e14f72e27b3d170293ef7935fc9455ff5e
MD5 969cfc4bc0b0316261a366bdb89573d9
BLAKE2b-256 f43d06bff3088385a0b2144bdbf0345c20650df6e6f24005552094ba299828e0

See more details on using hashes here.

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