trengrj / recent

log bash history to an sqlite database
MIT License
53 stars 2 forks source link

<enter> on blank prompt results in duplicate entries #3

Closed wagoodman closed 8 years ago

wagoodman commented 8 years ago

Great tool, btw! I'm having a small issue with it: When you hit on an empty prompt, a new entry is added to the recent.db that reflects the last full command run. For instance:

$ ls
...
$ clear
$ recent
2016-10-28 12:46:08 ls
2016-10-28 12:46:10 clear

Now hit a few times and see what recent says:

$
$
$
$
$ recent
2016-10-28 12:46:08 ls
2016-10-28 12:46:10 clear
2016-10-28 12:46:12 recent
2016-10-28 12:47:33 recent
2016-10-28 12:47:33 recent
2016-10-28 12:47:34 recent
2016-10-28 12:47:34 recent
$ 

This shows the last command (in this case recent) correctly being logged at 12:46:12, but incorrectly logged when on 12:47:33 and 12:47:34 (twice each).

I suspect a similar trick as listed here may help.

trengrj commented 8 years ago

Thanks @wagoodman, this was definitely an issue.

I've fixed this in version 0.1.1. You can upgrade via sudo pip install recent --upgrade.

As you mentioned it is due to the history 1 not updating when an empty command is run. This makes things a bit tricky and unfortunately there are no other good ways to get what was last entered from bash.

I fixed this by recording the sequence number that is returned from history 1. This had a throw-on effect that I now needed to manage sequences and sessions so that multiple bash terminals wouldn't interfere with each other. I've now created a separate sessions table in the database that records:

  1. last session update
  2. session create time
  3. device hostname
  4. term type
  5. user id at session creation
  6. the sequence number from history

The cool thing is that this is all now captured in the database.

I've started upgrading the recent command tool as well. You can now query dates and working directories so you can type stuff like recent -w . -d 2016 git to get git commands run in the current folder over 2016. Would appreciate any feedback you have.