diff --git a/cmd/cli/item.go b/cmd/cli/item.go index 58c4304..b30c513 100644 --- a/cmd/cli/item.go +++ b/cmd/cli/item.go @@ -14,6 +14,8 @@ import ( const itemLocationLenght = 30 type item struct { + isRaw bool + realtimeBefore float64 // [host:]pwd @@ -65,7 +67,23 @@ func (i item) less(i2 item) bool { // reversed order return i.score > i2.score } + func (i item) drawItemColumns(compactRendering bool) itemColumns { + if i.isRaw { + notAvailable := "n/a" + return itemColumns{ + date: notAvailable + " ", + dateWithColor: notAvailable + " ", + // dateWithColor: highlightDate(notAvailable) + " ", + host: "", + hostWithColor: "", + pwdTilde: notAvailable, + cmdLine: i.cmdLine, + cmdLineWithColor: i.cmdLineWithColor, + // score: i.score, + key: i.key, + } + } // DISPLAY // DISPLAY > date @@ -80,7 +98,6 @@ func (i item) drawItemColumns(compactRendering bool) itemColumns { date = formatTimeRelativeLong(tm) + " " } dateWithColor := highlightDate(date) - // DISPLAY > location // DISPLAY > location > host host := "" @@ -232,6 +249,31 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool // NO continue } } + // DISPLAY > cmdline + + // cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">" + cmdLine := strings.ReplaceAll(record.CmdLine, "\n", ";") + cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";") + + // KEY for deduplication + + key := record.CmdLine + // NOTE: since we import standard history we need a compatible key without metadata + /* + unlikelySeparator := "|||||" + key := record.CmdLine + unlikelySeparator + record.Pwd + unlikelySeparator + + record.GitOriginRemote + unlikelySeparator + record.Host + */ + if record.IsRaw { + return item{ + isRaw: true, + + cmdLine: cmdLine, + cmdLineWithColor: cmdLineWithColor, + score: score, + key: key, + }, nil + } // actual pwd matches // N terms can only produce: // -> N matches against the command @@ -265,19 +307,6 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool return item{}, errors.New("no match for given record and query") } - // KEY for deduplication - - unlikelySeparator := "|||||" - key := record.CmdLine + unlikelySeparator + record.Pwd + unlikelySeparator + - record.GitOriginRemote + unlikelySeparator + record.Host - // + strconv.Itoa(record.ExitCode) + unlikelySeparator - - // DISPLAY > cmdline - - // cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">" - cmdLine := strings.ReplaceAll(record.CmdLine, "\n", ";") - cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";") - it := item{ realtimeBefore: record.RealtimeBefore, diff --git a/pkg/histcli/histcli.go b/pkg/histcli/histcli.go index 2abb799..f9b6611 100644 --- a/pkg/histcli/histcli.go +++ b/pkg/histcli/histcli.go @@ -22,3 +22,10 @@ func (h *Histcli) AddRecord(record records.Record) { h.List = append(h.List, cli) } + +// AddCmdLine to the histcli +func (h *Histcli) AddCmdLine(cmdline string) { + cli := records.NewCliRecordFromCmdLine(cmdline) + + h.List = append(h.List, cli) +} diff --git a/pkg/histfile/histfile.go b/pkg/histfile/histfile.go index a72da7d..b1d8019 100644 --- a/pkg/histfile/histfile.go +++ b/pkg/histfile/histfile.go @@ -50,7 +50,13 @@ func New(input chan records.Record, sessionsToDrop chan string, } // load records from resh history, reverse, enrich and save -func (h *Histfile) loadFullRecords(recs []records.Record) { +func (h *Histfile) loadCliRecords(recs []records.Record) { + for _, cmdline := range h.bashCmdLines.List { + h.cliRecords.AddCmdLine(cmdline) + } + for _, cmdline := range h.zshCmdLines.List { + h.cliRecords.AddCmdLine(cmdline) + } for i := len(recs) - 1; i >= 0; i-- { rec := recs[i] h.cliRecords.AddRecord(rec) @@ -82,7 +88,7 @@ func (h *Histfile) loadHistory(bashHistoryPath, zshHistoryPath string, maxInitHi } log.Println("histfile: Loading resh history from file ...") history := records.LoadFromFile(h.historyPath, math.MaxInt32) - go h.loadFullRecords(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 reshCmdLines := loadCmdLines(history) diff --git a/pkg/records/records.go b/pkg/records/records.go index 8696ef3..c4e91db 100644 --- a/pkg/records/records.go +++ b/pkg/records/records.go @@ -150,6 +150,7 @@ type SlimRecord struct { // CliRecord used for sending records to RESH-CLI type CliRecord struct { + IsRaw bool `json:"isRaw"` SessionID string `json:"sessionId"` CmdLine string `json:"cmdLine"` @@ -164,9 +165,18 @@ type CliRecord struct { // RealtimeDuration float64 `json:"realtimeDuration"` } +// NewCliRecordFromCmdLine from EnrichedRecord +func NewCliRecordFromCmdLine(cmdLine string) CliRecord { + return CliRecord{ + IsRaw: true, + CmdLine: cmdLine, + } +} + // NewCliRecord from EnrichedRecord func NewCliRecord(r EnrichedRecord) CliRecord { return CliRecord{ + IsRaw: false, SessionID: r.SessionID, CmdLine: r.CmdLine, Host: r.Host,