This is born from my switch to using the Oh-My-Zsh plugin for directory history, per-directory-history. Initially I was satisfied with a simple function to grep through the .directory_history to find historical commands:
function sdh() { find ~/.directory_history/**/history -exec grep "$@" {} + | cut -d';' -f2 | sort | uniq; }
Sometimes I would find that I might want to know the source directory of where I ran those commands, so I could get some additional context of the commands just prior and just after. Context is what keeps me using directory history, and I suspect was a driver for the initial concept. So I've jotted down a few things that I would like a searching tool to do, and started creating search-directory-history
.
- Basic Search - return commands from a single keyword search
- Intermediate Search - & and | for multi-keyword searching
- Advanced RegEx Searching - return commands matching a passed in regex
- Output - terse/verbose/specified fields
- search
- Verbs
-
--multiline
- show entire multi-line commands -
--startpath
- start the search at a specific path:~/.directory_history/home/myuid/src/
- specified as
/home/myuid/src
- specified as
-
--searchfrom
- timeframe in 4d, 3w, 2m, 1y -
--searchduration
- timeframe in 1d, 1w, 1m, 1y, starting from--searchfrom
- defaults to
--searchfrom
- defaults to
-
--terse
-
--context
- number of context commands to display on either side of match- for troubleshooting/identification of context lines, a -/=/+ was used to indicate
- if a command comes before (-), is the match (=), or is after (+)
- basic functionality is working, would like to make it work more like diff with context
- command line completions, looks like Cobra framework has the ability to spit out completion scripts.
-
--verbose
-
--fields
- csv list of field names"date,directory,command"
-
--output
- json,table,text,yaml?
-
- Verbs
- help