mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
peco --print-query prints out the query as first line
This commit is contained in:
parent
b9a1bbec36
commit
d25a14bf40
|
|
@ -82,6 +82,7 @@ type Peco struct {
|
|||
maxScanBufferSize int
|
||||
mutex sync.Mutex
|
||||
onCancel string
|
||||
printQuery bool
|
||||
prompt string
|
||||
query Query
|
||||
queryExecDelay time.Duration
|
||||
|
|
@ -407,6 +408,7 @@ type CLIOptions struct {
|
|||
OptOnCancel string `long:"on-cancel" description:"specify action on user cancel. 'success' or 'error'.\ndefault is 'success'. This may change in future versions"`
|
||||
OptSelectionPrefix string `long:"selection-prefix" description:"use a prefix instead of changing line color to indicate currently selected lines.\ndefault is to use colors. This option is experimental"`
|
||||
OptExec string `long:"exec" description:"execute command instead of finishing/terminating peco.\nPlease note that this command will receive selected line(s) from stdin,\nand will be executed via '/bin/sh -c' or 'cmd /c'"`
|
||||
OptPrintQuery bool `long:"print-query" descritpion:"print out the current query as first line of output"`
|
||||
}
|
||||
|
||||
type CLI struct {
|
||||
|
|
|
|||
6
peco.go
6
peco.go
|
|
@ -532,6 +532,7 @@ func (p *Peco) ApplyConfig(opts CLIOptions) error {
|
|||
p.selectionPrefix = p.config.SelectionPrefix
|
||||
}
|
||||
p.selectOneAndExit = opts.OptSelect1
|
||||
p.printQuery = opts.OptPrintQuery
|
||||
p.initialQuery = opts.OptQuery
|
||||
p.initialFilter = opts.OptInitialFilter
|
||||
if len(p.initialFilter) <= 0 {
|
||||
|
|
@ -728,6 +729,11 @@ func (p *Peco) PrintResults() {
|
|||
}()
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
if p.printQuery {
|
||||
buf.WriteString(p.Query().String())
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
for line := range p.ResultCh() {
|
||||
buf.WriteString(line.Output())
|
||||
buf.WriteByte('\n')
|
||||
|
|
|
|||
Loading…
Reference in a new issue