23 ms·
Everyone's memory is better than mine: I can't even remember the command I typed, so I need to hunt it down from the context: current directory, date or previou
by Fileformat 3y ago
Everyone's memory is better than mine: I can't even remember the command I typed, so I need to hunt it down from the context: current directory, date or previous commands.
I use a zsh precmd() along the lines of
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(fc -ln -1)" >> ~/bash/bash-history-$(date "+%Y-%m-%d").log;
Should be doable with bash's PROMPT_COMMAND if you are still on bash
- tripflag 3y agoWe have a lot in common :-P except I'm still on bash, and do rely on PROMPT_COMMAND like you mentioned -- https://github.com/9001/asm/blob/hovudstraum/etc/profile.d/env.sh#L2-L24 https://github.com/9001/asm/blob/hovudstraum/etc/profile.d/e... Lines 11-21 can be ignored, they detect if the folder you were in got moved/deleted from another shell, to avoid the confusing behavior you get in that case.
- JNRowe 3y agozsh has a comprehensive hook system available for these types of tasks¹(zshaddhistory in this case). It gives you more options to control how/when the history is preserved, and allows you to be more selective in when it should be written. Possibly worth noting for others that you'd want to think this through if you're using any of the history eliding options(hist_ignore_space² for example), as one history file may contain secrets when you're really expecting that it wouldn't. There is also a better interface to work with hook functions through the add-zsh-hook mechanism³, which allows stacking multiple hook functions together. ¹ https://zsh.sourceforge.io/Doc/Release/Functions.html#index-history_002c-hook-when-line-is-saved https://zsh.sourceforge.io/Doc/Release/Functions.html#index-... ² https://zsh.sourceforge.io/Doc/Release/Options.html#History https://zsh.sourceforge.io/Doc/Release/Options.html#History ³ https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#Manipulating-Hook-Functions https://zsh.sourceforge.io/Doc/Release/User-Contributions.ht...
- csdvrx 3y ago> Should be doable with bash's PROMPT_COMMAND if you are still on bash Already done, with also PS0 and a sqlite backend: https://github.com/csdvrx/bash-timestamping-sqlite https://github.com/csdvrx/bash-timestamping-sqlite