Output unmodified command lines from search

Fixes: #152
pull/184/head
Simon Let 3 years ago
parent cd611e9ac4
commit 651ace4ec4
  1. 8
      cmd/cli/main.go
  2. 10
      internal/searchapp/item.go

@ -200,13 +200,13 @@ func (m manager) SelectExecute(g *gocui.Gui, v *gocui.View) error {
defer m.s.lock.Unlock() defer m.s.lock.Unlock()
if m.s.rawMode { if m.s.rawMode {
if m.s.highlightedItem < len(m.s.rawData) { if m.s.highlightedItem < len(m.s.rawData) {
m.s.output = m.s.rawData[m.s.highlightedItem].CmdLine m.s.output = m.s.rawData[m.s.highlightedItem].CmdLineOut
m.s.exitCode = exitCodeExecute m.s.exitCode = exitCodeExecute
return gocui.ErrQuit return gocui.ErrQuit
} }
} else { } else {
if m.s.highlightedItem < len(m.s.data) { if m.s.highlightedItem < len(m.s.data) {
m.s.output = m.s.data[m.s.highlightedItem].CmdLine m.s.output = m.s.data[m.s.highlightedItem].CmdLineOut
m.s.exitCode = exitCodeExecute m.s.exitCode = exitCodeExecute
return gocui.ErrQuit return gocui.ErrQuit
} }
@ -219,13 +219,13 @@ func (m manager) SelectPaste(g *gocui.Gui, v *gocui.View) error {
defer m.s.lock.Unlock() defer m.s.lock.Unlock()
if m.s.rawMode { if m.s.rawMode {
if m.s.highlightedItem < len(m.s.rawData) { if m.s.highlightedItem < len(m.s.rawData) {
m.s.output = m.s.rawData[m.s.highlightedItem].CmdLine m.s.output = m.s.rawData[m.s.highlightedItem].CmdLineOut
m.s.exitCode = 0 // success m.s.exitCode = 0 // success
return gocui.ErrQuit return gocui.ErrQuit
} }
} else { } else {
if m.s.highlightedItem < len(m.s.data) { if m.s.highlightedItem < len(m.s.data) {
m.s.output = m.s.data[m.s.highlightedItem].CmdLine m.s.output = m.s.data[m.s.highlightedItem].CmdLineOut
m.s.exitCode = 0 // success m.s.exitCode = 0 // success
return gocui.ErrQuit return gocui.ErrQuit
} }

@ -31,8 +31,11 @@ type Item struct {
sameGitRepo bool sameGitRepo bool
exitCode int exitCode int
// Shown in TUI
CmdLineWithColor string CmdLineWithColor string
CmdLine string CmdLine string
// Unchanged cmdline to paste to command line
CmdLineOut string
Score float64 Score float64
@ -375,8 +378,8 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo
// DISPLAY > cmdline // DISPLAY > cmdline
// cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">" // cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">"
cmdLine := strings.ReplaceAll(record.CmdLine, "\n", ";") cmdLine := strings.ReplaceAll(record.CmdLine, "\n", "\\n ")
cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";") cmdLineWithColor := strings.ReplaceAll(cmd, "\n", "\\n ")
// KEY for deduplication // KEY for deduplication
@ -391,6 +394,7 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo
return Item{ return Item{
isRaw: true, isRaw: true,
CmdLineOut: record.CmdLine,
CmdLine: cmdLine, CmdLine: cmdLine,
CmdLineWithColor: cmdLineWithColor, CmdLineWithColor: cmdLineWithColor,
Score: score, Score: score,
@ -443,6 +447,7 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo
sameGitRepo: sameGitRepo, sameGitRepo: sameGitRepo,
exitCode: record.ExitCode, exitCode: record.ExitCode,
CmdLineOut: record.CmdLine,
CmdLine: cmdLine, CmdLine: cmdLine,
CmdLineWithColor: cmdLineWithColor, CmdLineWithColor: cmdLineWithColor,
Score: score, Score: score,
@ -480,6 +485,7 @@ func GetHeader(compactRendering bool) ItemColumns {
type RawItem struct { type RawItem struct {
CmdLineWithColor string CmdLineWithColor string
CmdLine string CmdLine string
CmdLineOut string
Score float64 Score float64

Loading…
Cancel
Save