44 lines
927 B
Go
44 lines
927 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
//"github.com/vbatts/go-gdbm"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
var (
|
|
loadNew = true
|
|
flBashHistoryFile = flag.String("hist", path.Join(os.Getenv("HOME"), ".bash_history"), "path to the bash history file")
|
|
flDb = flag.String("db", path.Join(os.Getenv("HOME"), ".shell_history.db"), "path to database")
|
|
flList = flag.Bool("l", false, "list all commands stored")
|
|
flQuiet = flag.Bool("q", false, "less output")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
db, err := NewDatabase(*flDb)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
defer db.Close()
|
|
if *flList {
|
|
loadNew = false
|
|
}
|
|
|
|
fmt.Println(db)
|
|
|
|
if loadNew {
|
|
// TODO parse the bash history and load each
|
|
if err := db.InsertCommand(0, "ls -lh"); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
}
|
|
if err := db.InsertCommand(2, "ls -lh"); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
}
|
|
}
|
|
}
|