refactor: rename shist to verbatim

This commit is contained in:
Viktor Varland 2026-02-16 19:54:28 +01:00
parent 533775dfe3
commit dd65cb632f
No known key found for this signature in database
GPG key ID: 991E991EBEC46432
6 changed files with 27 additions and 25 deletions

View file

@ -10,14 +10,14 @@ git clone git.meatbag.se:vlv/shell-history.git shell-history
mkdir histdb
cd shell-history
go build -o shist .
sudo install shist /usr/local/bin/
go build -o verbatim .
sudo install verbatim /usr/local/bin/
```
## Migrate from log files
```
shist import ~/dev/vlv/histdb/
verbatim import ~/dev/vlv/histdb/
```
## zsh
@ -33,7 +33,7 @@ _add_history() {
if test "$(id -u)" -ne 0; then
local cmd=$(fc -ln -1)
cmd=${cmd//$'\n'/\\n}
shist add \
verbatim add \
--timestamp "$(date -u +%Y-%m-%dT%H:%M:%S+00:00)" \
--hostname "$(hostname)" \
--dir "$(pwd)" \
@ -42,7 +42,7 @@ _add_history() {
}
add-zsh-hook precmd _add_history
hsup() { shist sync "$histdb_dir" }
hsup() { verbatim sync "$histdb_dir" }
hs() {
local copy_cmd=
@ -57,10 +57,10 @@ hs() {
esac
local entry="$(
shist search "$@" | \
verbatim search "$@" | \
fzf --ansi --disabled --query "${*:-}" \
--bind "start:reload:shist search {q}" \
--bind "change:reload:sleep 0.1; shist search {q} || true" \
--bind "start:reload:verbatim search {q}" \
--bind "change:reload:sleep 0.1; verbatim search {q} || true" \
--delimiter ' '
)"
@ -77,14 +77,14 @@ hs() {
## Usage
```
shist [--db PATH] add --timestamp T --hostname H --dir D -- COMMAND...
shist [--db PATH] search [--host H] [--dir D] [--after T] [--before T] [--limit N] [QUERY...]
shist [--db PATH] sync DIR
shist [--db PATH] import DIR
shist [--db PATH] stats
verbatim [--db PATH] add --timestamp T --hostname H --dir D -- COMMAND...
verbatim [--db PATH] search [--host H] [--dir D] [--after T] [--before T] [--limit N] [QUERY...]
verbatim [--db PATH] sync DIR
verbatim [--db PATH] import DIR
verbatim [--db PATH] stats
```
Default `--db`: `~/.local/share/shist/history.db`
Default `--db`: `~/.local/share/verbatim/history.db`
## Legacy

View file

@ -16,7 +16,7 @@ func Run(d *sql.DB, args []string) error {
fs.Parse(args)
if *timestamp == "" || *hostname == "" || *dir == "" {
fmt.Fprintln(os.Stderr, "usage: shist add --timestamp T --hostname H --dir D -- COMMAND...")
fmt.Fprintln(os.Stderr, "usage: verbatim add --timestamp T --hostname H --dir D -- COMMAND...")
os.Exit(1)
}

View file

@ -12,7 +12,7 @@ import (
func Run(d *sql.DB, args []string) error {
if len(args) < 1 {
fmt.Fprintln(os.Stderr, "usage: shist import DIR")
fmt.Fprintln(os.Stderr, "usage: verbatim import DIR")
os.Exit(1)
}

View file

@ -42,13 +42,15 @@ func Run(d *sql.DB, args []string) error {
params = append(params, *before)
}
q := "SELECT timestamp, hostname, working_dir, command FROM history"
inner := "SELECT timestamp, hostname, working_dir, command FROM history"
if len(where) > 0 {
q += " WHERE " + strings.Join(where, " AND ")
inner += " WHERE " + strings.Join(where, " AND ")
}
q += " ORDER BY timestamp DESC LIMIT ?"
inner += " ORDER BY timestamp DESC LIMIT ?"
params = append(params, *limit)
q := "SELECT * FROM (" + inner + ") ORDER BY timestamp ASC"
rows, err := d.Query(q, params...)
if err != nil {
return err

View file

@ -15,7 +15,7 @@ import (
func Run(d *sql.DB, args []string) error {
if len(args) < 1 {
fmt.Fprintln(os.Stderr, "usage: shist sync DIR")
fmt.Fprintln(os.Stderr, "usage: verbatim sync DIR")
os.Exit(1)
}
gitDir := args[0]

10
main.go
View file

@ -15,7 +15,7 @@ import (
)
func main() {
global := flag.NewFlagSet("shist", flag.ExitOnError)
global := flag.NewFlagSet("verbatim", flag.ExitOnError)
dbPath := global.String("db", defaultDBPath(), "path to database")
global.Usage = usage
global.Parse(os.Args[1:])
@ -30,7 +30,7 @@ func main() {
d, err := db.Open(*dbPath)
if err != nil {
fmt.Fprintf(os.Stderr, "shist: %v\n", err)
fmt.Fprintf(os.Stderr, "verbatim: %v\n", err)
os.Exit(1)
}
defer d.Close()
@ -51,7 +51,7 @@ func main() {
}
if err != nil {
fmt.Fprintf(os.Stderr, "shist %s: %v\n", cmd, err)
fmt.Fprintf(os.Stderr, "verbatim %s: %v\n", cmd, err)
os.Exit(1)
}
}
@ -61,11 +61,11 @@ func defaultDBPath() string {
if err != nil {
return "history.db"
}
return filepath.Join(home, ".local", "share", "shist", "history.db")
return filepath.Join(home, ".local", "share", "verbatim", "history.db")
}
func usage() {
fmt.Fprintln(os.Stderr, `usage: shist [--db PATH] <command> [flags]
fmt.Fprintln(os.Stderr, `usage: verbatim [--db PATH] <command> [flags]
commands:
add record a command