diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 1578643..0c18cc7 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -622,5 +622,8 @@ func SendCliMsg(m msg.CliMsg, port string) msg.CliResponse { if err != nil { log.Fatal("unmarshal resp error: ", err) } + if debug { + log.Printf("recieved %d records from daemon\n", len(response.CliRecords)) + } return response } diff --git a/pkg/histfile/histfile.go b/pkg/histfile/histfile.go index b1d8019..0e32d05 100644 --- a/pkg/histfile/histfile.go +++ b/pkg/histfile/histfile.go @@ -61,6 +61,7 @@ func (h *Histfile) loadCliRecords(recs []records.Record) { rec := recs[i] h.cliRecords.AddRecord(rec) } + log.Println("histfile: resh history loaded - history records count:", len(h.cliRecords.List)) } // loadsHistory from resh_history and if there is not enough of it also load native shell histories @@ -88,6 +89,7 @@ func (h *Histfile) loadHistory(bashHistoryPath, zshHistoryPath string, maxInitHi } log.Println("histfile: Loading resh history from file ...") history := records.LoadFromFile(h.historyPath, math.MaxInt32) + log.Println("histfile: resh history loaded from file - count:", len(history)) go h.loadCliRecords(history) // NOTE: keeping this weird interface for now because we might use it in the future // when we only load bash or zsh history diff --git a/pkg/records/records.go b/pkg/records/records.go index c4e91db..6271ba5 100644 --- a/pkg/records/records.go +++ b/pkg/records/records.go @@ -524,14 +524,17 @@ func LoadFromFile(fname string, limit int) []Record { } defer file.Close() - scanner := bufio.NewScanner(file) + reader := bufio.NewReader(file) var i int var firstErrLine int - for scanner.Scan() { + for { + line, err := reader.ReadString('\n') + if err != nil { + break + } i++ record := Record{} fallbackRecord := FallbackRecord{} - line := scanner.Text() err = json.Unmarshal([]byte(line), &record) if err != nil { err = json.Unmarshal([]byte(line), &fallbackRecord) @@ -550,6 +553,11 @@ func LoadFromFile(fname string, limit int) []Record { } recs = append(recs, record) } + // log.Println("records: done loading file:", err) + if err != io.EOF { + log.Println("records: error while loading file:", err) + } + // log.Println("records: Loaded lines - count:", i) if encounteredErrors > 0 { // fix errors in the history file log.Printf("There were %d decoding errors, the first error happend on line %d/%d", encounteredErrors, firstErrLine, i) @@ -564,6 +572,7 @@ func LoadFromFile(fname string, limit int) []Record { log.Fatalln("Fatal: Failed write out new history") } } + log.Println("records: Loaded records - count:", len(recs)) return recs }