|
I have a simpler solution. The use case is not precisely the same, but for many scenarios, it's effectively the same. Simply, like many, I have bash set up to record commands in .bash_history. I have it flush all the time, so .bash_history is always current. # keep persistent bash history across sessions
export PROMPT_COMMAND='history -a;history -n'
export HISTCONTROL=ignoredups
shopt -s histappend
Next, I have a simple cron job running every minute. file=/tmp/work.$$
cat ~/.bash_history ~/.unique_bash | grep -v findcmd | sort -u > $file
mv $file ~/.unique_bash
Then, I have a script called "findcmd" that simply greps my .unique_bash file. for var in "$@"
do
cmd="| grep \"$var\" $cmd"
done
cmd="cat ~/.unique_bash $cmd"
eval $cmd
In the end, when I need to figure something out, I head to the internet. Those commands are then captured for posterity in the .unique_bash file. If I want to know how to post a JSON file to an endpoint using Curl, then $ findcmd curl json
And all those curl commands show up.It won't let me do something I don't know, but it make my memory much, much longer. And, yea, I admit there have been instances where I've completely forgotten the command, and had to head back to the web. But when I've done that, I can hit my history and see how I used it. If, sometimes, a "bad command", a command done wrong, too many of the same thing, just lingers, I can go edit it out. But most of the time I don't bother. |
Link: https://github.com/junegunn/fzf
In particular, shell key bindings for fzf: https://github.com/junegunn/fzf#key-bindings-for-command-lin...