4 ms·
I recently set up my bash history to collect into an sqlite database. Besides the exact command it records the working directory, return value, starting time, e
by leni536 11y ago
I recently set up my bash history to collect into an sqlite database. Besides the exact command it records the working directory, return value, starting time, ending time, a shell and a login session id. It doesn't handle background jobs well right now though.
- nyir 11y agoOkay I'm curious as to why? I mean it's nice to have, but what are you going to do with the additional data later on?
- leni536 11y agoIt was mainly for an exercise to get familiar with sqlite. Maybe later very rarely I can use the session data (hunting down sessions where you only remember some irrelevant command). Getting the duration of some commands is useful like long running simulations, compilations. It's especially handy where you don't expect it to be too long and forget to time it beforehand. Having said that I didn't use it too much yet, I have my regular history in place too.
- caipre 11y agozsh has an option to automatically print the time of commands exceeding a threshold. See here for a brief example: http://nuclearsquid.com/writings/reporttime-in-zsh/ http://nuclearsquid.com/writings/reporttime-in-zsh/
- saurik 11y agoI maintain almost all my bash history and I often use it to reconstruct a sequence of events in the past when I feel like maybe a mistake had been made.
- anc84 11y agoI would love to use this! Had to grep through ancient backup diffs way too many times to resurrect that perfect command line.
- dspillett 11y agoI was interested myself too so had a quick search. There are a couple of implementations of the idea out there, https://code.google.com/p/advanced-shell-history/ https://code.google.com/p/advanced-shell-history/ looks the most promising of the ones I looked at. I might have to play with it later.
- DEinspanjer 11y agoDo you have any links to resources you used to build it or better yet a link to your implementation? I've been pretty happy with my bash history solution, but thinking about the return value, one big thing I think would be handy would be to have a default filter for searches that removes commands that returned an error code. They might be handy to see every once in a while, but for the most part, I wouldn't want to re-run one of them.
- leni536 11y agohttp://pastebin.com/zJkPW79C http://pastebin.com/zJkPW79C I use bash-preexec [1] to hook on the even just before executing a command. I'm kind of nervous if my string quoting is safe though. [1] https://github.com/rcaloras/bash-preexec https://github.com/rcaloras/bash-preexec