need a package to read/write shell history flat file database

94 views
Skip to first unread message

Kurtis Rader

unread,
Feb 10, 2024, 9:56:24 PMFeb 10
to golang-nuts
I'm looking for a package that will read/write a flat file database of shell commands from multiple processes. I could take an existing implementation in a different language, such as the one used by Bash or Fish, and rewrite it in Go but was hoping someone has already done this. The specific structure (e.g., YAML, JSON, something else) isn't important. I'm just looking for an implementation that is known to correctly handle appending new entries from concurrently running processes and rewriting the file when entries are deleted.

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Kurtis Rader

unread,
Feb 11, 2024, 12:02:28 AMFeb 11
to golang-nuts
The only solution I can find that gets close to my requirements is https://github.com/ergochat/readline, but AFAICT it does not handle updates to the on-disk history file by concurrently executing processes.

Dan Kortschak

unread,
Feb 11, 2024, 12:15:58 AMFeb 11
to golan...@googlegroups.com
On Sat, 2024-02-10 at 21:01 -0800, Kurtis Rader wrote:
> The only solution I can find that gets close to my requirements is
> https://github.com/ergochat/readline, but AFAICT it does not handle
> updates to the on-disk history file by concurrently executing
> processes.

There is also https://pkg.go.dev/github.com/peterh/liner, which also
does not handle history persistence, but which makes it relatively easy
to add.

Kurtis Rader

unread,
Feb 11, 2024, 12:41:11 AMFeb 11
to Dan Kortschak, golan...@googlegroups.com
Thanks, but that requires me to implement the code I would rather not have to reinvent given that shells like Bash, Ksh, and Fish already have code to do what I need. The problem is that those solutions are written in C and C++ respectively rather than Go. While I consider myself an expert in C (having started programming with it around 1985) I am only minimally competent in C++. I'll translate the Fish C++ code into Go if I have to but am hoping there is a published Go equivalent to save me that effort.

P.S., This is to remove the dependency on a daemon process to update a BoltDB database by the Fish shell. The BoltDB dependency (go.etcd.io/bbolt) greatly increases the size and complexity of the Fish shell. The opaque binary database managed by BoltDB is also annoying. It would be preferable to use a flat file database using JSON or text protobufs for storing command history.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e37a98a811c8e1cccfef8feffafef5260e7e5e56.camel%40kortschak.io.

Marcello H

unread,
Feb 12, 2024, 3:25:51 AMFeb 12
to golang-nuts
This package (FZF) is also using the history file, perhaps there's something usable inside.
https://github.com/junegunn/fzf

Op zondag 11 februari 2024 om 06:41:11 UTC+1 schreef Kurtis Rader:
Reply all
Reply to author
Forward
0 new messages