Package: recent2
RecentRecent is a more structured way to log your bash history.The standard~/.bash_historyfile is inadequate in many ways, its
worst fault is to by default log only 500 history entries, with no timestamp.
You can alter your bashHISTFILESIZEandHISTTIMEFORMATvariables but it
is still a unstructured format with limited querying ability.Recent does the following.Logs current localtime, command text, current pid, command return value,
working directory to an sqlite database in~/.recent.db.Logs history immediately, rather than at the close of the session.Provides a command calledrecentfor searching bash history.NOTE abouttrengrj/recentrecent2started off as a clone oftrengrj/recent.
I usedtrengrj'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 core logic is written bytrengrj. I added
a lot of incremental patches for the things that interested me. I intend to actively
maintain this as I see more interesting use cases.Installation instructionsInstall the recent2 pip package via pip (python 3)pip3 install recent2Add the following to your.bashrcor.bash_profile.export PROMPT_COMMAND='log-recent -r $? -c "$(HISTTIMEFORMAT= history 1)" -p $$'And start a new shell.UsageSee example usage athttps://asciinema.org/a/271533Help Text>recent-h
usage:recent[-h][-n20][--status_num0][--successes_only][--failures_only][-w/folder][--cur_session_only][-d2016-10-01][--return_self][--char_limit200][--envkey[:val]][--hide_time][--debug][--detail][--columnsCOLUMNS][-re][-sql][--nocase][pattern]recentisaconvenientwaytoquerybashhistory.Visit
https://github.com/dotslash/recent2formoreexamplesortoask
questionsortoreportissues

positionalarguments:patternoptionalpatterntosearch

optionalarguments:-h,--helpshowthishelpmessageandexit-n20maxresultstoreturn--status_num0,-stn0intexitstatusofthecommandstoreturn.-1=>returnall.--successes_only,-soonlyreturncommandsthatexitedwithsuccess--failures_only,-foonlyreturncommandsthatexitedwithfailure-w/folderworkingdirectory--cur_session_only,-csReturnscommandsonlyfromcurrentsession-d2016-10-01dateinYYYY-MM-DD,YYYY-MM,orYYYYformat--return_selfReturn`recent`commandsalsointheoutput--char_limit200,-cl200Ignorecommandslongerthanthis.--envkey[:val],-ekey[:val]Filterbyshellenvvars.EnvvarssetinRECENT_ENV_VARSascommaseparatedlistwillbecaptured.--hide_time,-htdontdisplaytimeincommandoutput--debugDebugmode--detailReturndetailedoutput--columnsCOLUMNSCommaseparatedcolumnstoprintif--detailispassed.Validcolumnsarecommand_dt,command,pid,return_val,pwd,session,json_data-reenableregexsearchpattern-sqlenablesqlitesearchpattern--nocase,-ncIgnorecasewhensearchingforpatterns

Toimportbashhistoryintorecentdbrunrecent-import-bash-historyLook at your current history using recent. Here are some examples on how to use recent.Basic examples# Look for all git commandsrecentgit# Look for git commit commands. Query via regexp mode.recent-regit.*commitLess basic usageFilter commands by exit statusrecent git --successes_onlyorrecent git -sorecent git --failures_onlyorrecent git -forecent git --status_num 1orrecent git -stn 1returns only the git commands that have exit status 1.recent git --return_self. By defaultrecentcommands are not displayed in the output. Pass thereturn_selfto change that.recent git -w ~/code. This returns only the commands that were executed with~/codeas current working directory.Filter the commands by execution date by doingrecent git -d 2019orrecent git -d 2019-10orrecent git -d 2019-10-04By default recent prints command timestamp and the command in the output. Userecent git --hide_timeorrecent git -htto hide the command timestamp. This is useful when copy-pasting commands from output.Copy paste errors into the shell can result in random junk coming up
in the bash history. While-sooption mostly takes care of this,
another way to tackle this is to not show commands that are longer
than a given limit. The default is 200. If you want longer commands,
then dorecent git --char_limit 10000orrecent git -cl 10000Usage via sqliteIt is possible directly interact with sqlite if all the above options have failed you. See the table schema below.CREATETABLEcommands(command_dttimestamp,commandtext,pidint,return_valint,pwdtext,sessiontext);CREATEINDEXcommand_dt_indoncommands(command_dt);option1:recent -sql 'command like "%git%" and command not like "%commit%"'option2: You can directly play around with sqlitesqlite3 ~/.recent.db "select * from commands limit 10"FAQsQ: Can I have a custom location to store my history sqlite file?A: Yes. Point RECENT_DB environment variable to your sqlite file.Q: I want to have a custom PROMPT_COMMAND that calls log-recent using my own logic. How do I do that?A: This is basicallyhttps://github.com/dotslash/recent2/issues/32. Set RECENT_CUSTOM_PROMPT environment variable
to a non empty value.Dev installation instructionsgitclonehttps://github.com/dotslash/recent2&&cdrecent2
pipinstall-e.