4 ms·
Can fzf or the shell history file answer this question? zsh records timestamps and runtime if extended history is enabled. bash needs HISTTIMEFORMAT to be confi
by rzzzt 3y ago
Can fzf or the shell history file answer this question? zsh records timestamps and runtime if extended history is enabled. bash needs HISTTIMEFORMAT to be configured properly. I haven't used fzf so not sure if it can search by timestamp, I only see a line number for the matching command (presumably) in the gif.
- defrost 3y agoFWiW the authors setup: Here’s the ZSH configuration I used for many, many years: possibly cannot fully answer the question as there are settings to scrub duplicate commands ... meaning the target day will show commands unique to that day but not necessarily all commands from that day. It's a small quibble but potentially an issue for those that really need to Indiana Jones their command history for some specific clue.
- rzzzt 3y agoI agree, especially if the focus is not on the command itself but the date. Atuin has a CLI switch for filtering command history by date, but I don't see any support in the ctrl-r UI eg. with an operator like "before:" or similar.
- defrost 3y agoIn my own case large clumps of similar commands hinge upon what was the CD <current directory> at the time ... and the command most likely in many cases to be scrubbed as duplicate is a cd <one of 50 common working base directories>. This leads to "I can see I tidied up a bunch of project files first monday of last month ... but which project was that??"
- misnome 3y agoA nice thing that zsh (and bash-preexec) has is that you can add arbitrary functions to be called on command execution. I work at a large facility with a shared filesystem and many computers, so often I need to answer questions like “What did I run the last time I was sitting at computer X”. I log: command, timestamp, PID (to separate terminal streams), hostname and cwd. I’ve set up ctrl-r to search this “.fullhistory” file instead.
- salohcin 3y agoThis sounds interesting! Can you elaborate further?
- misnome 3y agoThe function: if [[ -n ${ZSH_VERSION-} ]]; then # ZSH doesn't split command over multiple variables preexec_custom_history() { echo "$HOSTNAME:\"$PWD\" $$ $(date "+%Y-%m-%dT%H:%M:%S%z") $1" >> "$CUSTOM_HISTORY_FILE" } else preexec_custom_history() { echo "$HOSTNAME:\"$PWD\" $$ $(date "+%Y-%m-%dT%H:%M:%S%z") $*" >> "$CUSTOM_HISTORY_FILE" } fi # Add it to the array of functions to be invoked each time. preexec_functions+=(preexec_custom_history) It's harder to search for multiline but I haven't gotten to fixing that yet. I've thought about putting it into sqlite (pwd makes the file large) but since everything is on network filesystems I don't think that's a place sqlite has any guarantees; screwing up a single line of a bare log doesn't break anything. Edit: The fzf is kind of hacked together but is here: https://pastebin.com/sTxsvZAf https://pastebin.com/sTxsvZAf . It has a few bugs but nothing annoying enough to have made me fix it.
- 59nadir 3y agoAtuin (the tool mentioned later in the post) stores timestamps and CWDs for commands in a database, which is probably why the title is what it is. I've been using it for 6+ months and it's actually good. I also like having an sqlite database with my commands so I can search it even more freeform if I want.