鏡像自
https://github.com/quitesimpleorg/hs9001.git
synced 2024-11-25 03:32:36 +01:00
search: Allow searching for cwd
This commit is contained in:
父節點
250af52750
當前提交
595595c4cb
19
main.go
19
main.go
@ -137,10 +137,10 @@ func importFromStdin(conn *sql.DB) {
|
||||
}
|
||||
}
|
||||
|
||||
func search(conn *sql.DB, q string) list.List {
|
||||
queryStmt := "SELECT id, command, workdir, user, hostname FROM history WHERE command LIKE ? ORDER BY timestamp ASC"
|
||||
func search(conn *sql.DB, q string, workdir string) list.List {
|
||||
queryStmt := "SELECT id, command, workdir, user, hostname FROM history WHERE command LIKE ? AND workdir LIKE ? ORDER BY timestamp ASC"
|
||||
|
||||
rows, err := conn.Query(queryStmt, "%"+q+"%")
|
||||
rows, err := conn.Query(queryStmt, q, workdir)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
@ -255,18 +255,17 @@ func main() {
|
||||
if len(rs) == 2 {
|
||||
add(conn, NewHistoryEntry(rs[1]))
|
||||
}
|
||||
case "search": fallthrough;
|
||||
case "search":
|
||||
fallthrough
|
||||
case "delete":
|
||||
var workDir string
|
||||
searchCmd.StringVar(&workDir, "workdir", "%", "Search only within this workdir")
|
||||
searchCmd.Parse(globalargs)
|
||||
|
||||
args := searchCmd.Args()
|
||||
|
||||
if len(args) < 1 {
|
||||
fmt.Fprint(os.Stderr, "Please provide the query\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
q := strings.Join(args, " ")
|
||||
results := search(conn, q)
|
||||
results := search(conn, "%"+q+"%", workDir)
|
||||
|
||||
for e := results.Front(); e != nil; e = e.Next() {
|
||||
entry, ok := e.Value.(*HistoryEntry)
|
||||
|
載入中…
新增問題並參考
Block a user