Support multi-line commands from zsh to fix #34

This commit is contained in:
David Dworken
2022-11-19 22:27:08 -08:00
parent f5adac5140
commit a390bacf89
11 changed files with 120 additions and 9 deletions

View File

@ -26,7 +26,7 @@ function __hishtory_on_control_r
set -l res $status
commandline -f repaint
if [ -s $tmp ]
commandline -r (cat $tmp)
commandline -r -- (cat $tmp)
end
rm -f $tmp
end

View File

@ -35,7 +35,7 @@ PROMPT_COMMAND="__hishtory_postcommand; $PROMPT_COMMAND"
export HISTTIMEFORMAT=$HISTTIMEFORMAT
__history_control_r() {
READLINE_LINE=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery "$READLINE_LINE" | tr -d '\n')
READLINE_LINE=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery "$READLINE_LINE")
READLINE_POINT=0x7FFFFFFF
}

View File

@ -24,7 +24,7 @@ function _hishtory_precmd() {
}
_hishtory_widget() {
BUFFER=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery $BUFFER | tr -d '\n')
BUFFER=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery $BUFFER)
CURSOR=${#BUFFER}
zle reset-prompt
}

View File

@ -0,0 +1,26 @@
Search Query: > Slah
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hostname Exit Code Command foo │
│─────────────────────────────────────────────────────────────────────────────│
│ ghaction-runner-hostname 0 ls -Slah / foo │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

View File

@ -0,0 +1,26 @@
Search Query: > Slah
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hostname Exit Code Command foo │
│─────────────────────────────────────────────────────────────────────────────│
│ ghaction-runner-hostname 0 ls -Slah / foo │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

View File

@ -0,0 +1,26 @@
Search Query: > Slah
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hostname Exit Code Command foo │
│─────────────────────────────────────────────────────────────────────────────│
│ ghaction-runner-hostname 0 ls \\n-Slah \\n/ foo │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

View File

@ -0,0 +1,2 @@
bash-5.2$ source /Users/david/.bashrc
bash-5.2$ ls -Slah /

View File

@ -0,0 +1,3 @@
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
david@Davids-MacBook-Air ~/c/hishtory (master)> ls -Slah /AppleInternal/

View File

@ -0,0 +1,3 @@
david@Davids-MacBook-Air hishtory % ls \
-Slah \
/

View File

@ -228,7 +228,7 @@ func getRows(ctx *context.Context, columnNames []string, query string, numEntrie
if strings.TrimSpace(entry.Command) == strings.TrimSpace(lastCommand) && config.FilterDuplicateCommands {
continue
}
entry.Command = strings.ReplaceAll(entry.Command, "\n", "; ")
entry.Command = strings.ReplaceAll(entry.Command, "\n", "\\n")
row, err := buildTableRow(ctx, columnNames, *entry)
if err != nil {
return nil, 0, fmt.Errorf("failed to build row for entry=%#v: %v", entry, err)
@ -454,6 +454,6 @@ func TuiQuery(ctx *context.Context, initialQuery string) error {
// Print out the initialQuery instead so that we don't clear the terminal
selectedRow = initialQuery
}
fmt.Printf("%s\n", selectedRow)
fmt.Printf("%s\n", strings.ReplaceAll(selectedRow, "\\n", "\n"))
return nil
}