@@ -0,0 +1,59 @@
1+package main
2+
3+import (
4+ "bufio"
5+ "os"
6+ "path/filepath"
7+
8+ lib "github.com/sacenox/lazy-history/lib"
9+)
10+
11+func main() {
12+
13+ query := os.Args[1] // args without program name
14+
15+ lib.Debugf("Query: %s", query)
16+
17+ history := []string{} // one cmd per entry
18+
19+ historyFilePaths := []string{
20+ filepath.Join(os.Getenv("HOME"), ".history"),
21+ filepath.Join(os.Getenv("HOME"), ".zsh_history"),
22+ filepath.Join(os.Getenv("HOME"), ".bash_history"),
23+ }
24+
25+ for _, historyFilePath := range historyFilePaths {
26+ if _, err := os.Stat(historyFilePath); os.IsNotExist(err) {
27+ lib.Debugf("History file %s does not exist", historyFilePath)
28+ continue
29+ }
30+
31+ historyFile, err := os.Open(historyFilePath)
32+ if err != nil {
33+ lib.Fatalf("Failed to open history file: %v", err)
34+ }
35+
36+ scanner := bufio.NewScanner(historyFile)
37+ // Read each line from the history file
38+ for scanner.Scan() {
39+ line := scanner.Text()
40+ history = append(history, line)
41+ }
42+
43+ lib.Debugf("Read %d lines from history file %s", len(history), historyFilePath)
44+
45+ // Check for scanner errors
46+ if err := scanner.Err(); err != nil {
47+ lib.Debugf("Error reading history file %s: %v", historyFilePath, err)
48+ }
49+
50+ historyFile.Close()
51+ }
52+
53+ results := lib.Search(history, query)
54+ // Print each line of the search results
55+ for _, result := range results {
56+ lib.Debugf("found: %s", result)
57+ }
58+
59+}