zsh-histdb

Check-in [59c50bcb9b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Notes about autosuggestions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 59c50bcb9b3e27c2103f53063cf03b2457aa26c1b36e6f8c088a40de91c5dc33
User & Date: tom.hinton@cse.org.uk 2017-04-26 15:33:34
Context
2017-05-03
15:19
Add some locals Leaf check-in: 6f91761e83 user: tom.hinton@cse.org.uk tags: master, trunk
2017-04-26
15:33
Notes about autosuggestions check-in: 59c50bcb9b user: tom.hinton@cse.org.uk tags: master, trunk
2017-04-25
14:12
Update sqlite-history.zsh check-in: 3eed9833e5 user: noreply@github.com tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to README.org.

56
57
58
59
60
61
62

































63
64
65
66
67
68
69
If there was more than one screenful, I would need to say ~--limit 1000~ or some other large number.
The command does not warn you if you haven't seen all the results.
The ~ses~ column contains a unique session number, so all the ~522~ rows are from the same shell session.

To see all hosts, add ~--host~ /after/ the query terms.
To see a specific host, add ~--host hostname~.
To see all of a specific session say e.g. ~-s 522 --limit 10000~.

































* Database schema
The database lives by default in ~$HOME/.histdb/zsh-history.db~.
You can look in it easily by running ~_histdb_query~, as this actually just fires up sqlite with the database.

For inspiration you can also use ~histdb~ with the ~-d~ argument and it will print the SQL it's running.
* Synchronising history
You should be able to synchronise the history using ~git~; a 3-way merge driver is supplied in ~histdb-merge~.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
If there was more than one screenful, I would need to say ~--limit 1000~ or some other large number.
The command does not warn you if you haven't seen all the results.
The ~ses~ column contains a unique session number, so all the ~522~ rows are from the same shell session.

To see all hosts, add ~--host~ /after/ the query terms.
To see a specific host, add ~--host hostname~.
To see all of a specific session say e.g. ~-s 522 --limit 10000~.
** Integration with ~zsh-autosuggestions~

If you use [[https://github.com/zsh-users/zsh-autosuggestions][zsh-autosuggestions]] you can configure it to search the history database instead of the ZSH history file thus:

#+BEGIN_SRC sh
  _zsh_autosuggest_strategy_histdb_top_here() {
      local query="select commands.argv from
  history left join commands on history.command_id = commands.rowid
  left join places on history.place_id = places.rowid
  where places.dir LIKE '$(sql_escape $PWD)%'
  and commands.argv LIKE '$(sql_escape $1)%'
  group by commands.argv order by count(*) desc limit 1"
      _histdb_query "$query"
  }

  ZSH_AUTOSUGGEST_STRATEGY=histdb_top_here
#+END_SRC

This query will find the most frequently issued command that is issued in the current directory or any subdirectory. You can get other behaviours by changing the query, for example

#+BEGIN_SRC sh
  _zsh_autosuggest_strategy_histdb_top() {
      local query="select commands.argv from
  history left join commands on history.command_id = commands.rowid
  left join places on history.place_id = places.rowid
  where commands.argv LIKE '$(sql_escape $1)%'
  group by commands.argv
  order by places.dir != '$(sql_escape $PWD)', count(*) desc limit 1"
      _histdb_query "$query"
  }
#+END_SRC

This will find the most frequently issued command issued exactly in this directory, or if there are no matches it will find the most frequently issued command in any directory. You could use other fields like the hostname to restrict to suggestions on this host, etc.
* Database schema
The database lives by default in ~$HOME/.histdb/zsh-history.db~.
You can look in it easily by running ~_histdb_query~, as this actually just fires up sqlite with the database.

For inspiration you can also use ~histdb~ with the ~-d~ argument and it will print the SQL it's running.
* Synchronising history
You should be able to synchronise the history using ~git~; a 3-way merge driver is supplied in ~histdb-merge~.