mirror of
https://github.com/ddworken/hishtory.git
synced 2025-04-25 01:48:56 +02:00
Support multi-line commands from zsh to fix #34
This commit is contained in:
parent
f5adac5140
commit
a390bacf89
@ -2047,12 +2047,37 @@ func testControlR(t *testing.T, tester shellTester, shellName string, onlineStat
|
|||||||
testutils.Check(t, err)
|
testutils.Check(t, err)
|
||||||
|
|
||||||
// And check that the control-r bindings work again
|
// And check that the control-r bindings work again
|
||||||
out = captureTerminalOutputWithShellName(t, tester, "fish", []string{"C-R", "-pipefail SPACE -exit_code:0"})
|
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "-pipefail SPACE -exit_code:0"})
|
||||||
if !strings.Contains(out, "\n\n\n") {
|
if strings.Contains(out, "\n\n\n") {
|
||||||
t.Fatalf("failed to find separator in %#v", out)
|
|
||||||
}
|
|
||||||
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
|
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
|
||||||
|
}
|
||||||
compareGoldens(t, out, "testControlR-Final")
|
compareGoldens(t, out, "testControlR-Final")
|
||||||
|
|
||||||
|
// Record a multi-line command
|
||||||
|
tester.RunInteractiveShell(t, ` hishtory enable`)
|
||||||
|
tester.RunInteractiveShell(t, `ls \
|
||||||
|
-Slah \
|
||||||
|
/`)
|
||||||
|
tester.RunInteractiveShell(t, ` hishtory disable`)
|
||||||
|
|
||||||
|
// Check that we display it in the table reasonably
|
||||||
|
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "Slah"})
|
||||||
|
if strings.Contains(out, "\n\n\n") {
|
||||||
|
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
|
||||||
|
}
|
||||||
|
compareGoldens(t, out, "testControlR-DisplayMultiline-"+shellName)
|
||||||
|
|
||||||
|
// Check that we can select it correctly
|
||||||
|
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "Slah", "Enter"})
|
||||||
|
if strings.Contains(out, "\n\n\n") {
|
||||||
|
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, "-Slah") {
|
||||||
|
t.Fatalf("out has unexpected output missing the selected row: \n%s", out)
|
||||||
|
}
|
||||||
|
if !testutils.IsGithubAction() {
|
||||||
|
compareGoldens(t, out, "testControlR-SelectMultiline-"+shellName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCustomColumns(t *testing.T, tester shellTester) {
|
func testCustomColumns(t *testing.T, tester shellTester) {
|
||||||
|
@ -26,7 +26,7 @@ function __hishtory_on_control_r
|
|||||||
set -l res $status
|
set -l res $status
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
if [ -s $tmp ]
|
if [ -s $tmp ]
|
||||||
commandline -r (cat $tmp)
|
commandline -r -- (cat $tmp)
|
||||||
end
|
end
|
||||||
rm -f $tmp
|
rm -f $tmp
|
||||||
end
|
end
|
||||||
|
@ -35,7 +35,7 @@ PROMPT_COMMAND="__hishtory_postcommand; $PROMPT_COMMAND"
|
|||||||
export HISTTIMEFORMAT=$HISTTIMEFORMAT
|
export HISTTIMEFORMAT=$HISTTIMEFORMAT
|
||||||
|
|
||||||
__history_control_r() {
|
__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
|
READLINE_POINT=0x7FFFFFFF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ function _hishtory_precmd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_hishtory_widget() {
|
_hishtory_widget() {
|
||||||
BUFFER=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery $BUFFER | tr -d '\n')
|
BUFFER=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery $BUFFER)
|
||||||
CURSOR=${#BUFFER}
|
CURSOR=${#BUFFER}
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
|
26
client/lib/goldens/testControlR-DisplayMultiline-bash
Normal file
26
client/lib/goldens/testControlR-DisplayMultiline-bash
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Search Query: > Slah
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ Hostname Exit Code Command foo │
|
||||||
|
│─────────────────────────────────────────────────────────────────────────────│
|
||||||
|
│ ghaction-runner-hostname 0 ls -Slah / foo │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
26
client/lib/goldens/testControlR-DisplayMultiline-fish
Normal file
26
client/lib/goldens/testControlR-DisplayMultiline-fish
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Search Query: > Slah
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ Hostname Exit Code Command foo │
|
||||||
|
│─────────────────────────────────────────────────────────────────────────────│
|
||||||
|
│ ghaction-runner-hostname 0 ls -Slah / foo │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
26
client/lib/goldens/testControlR-DisplayMultiline-zsh
Normal file
26
client/lib/goldens/testControlR-DisplayMultiline-zsh
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Search Query: > Slah
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ Hostname Exit Code Command foo │
|
||||||
|
│─────────────────────────────────────────────────────────────────────────────│
|
||||||
|
│ ghaction-runner-hostname 0 ls \\n-Slah \\n/ foo │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
│ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────────────┘
|
2
client/lib/goldens/testControlR-SelectMultiline-bash
Normal file
2
client/lib/goldens/testControlR-SelectMultiline-bash
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
bash-5.2$ source /Users/david/.bashrc
|
||||||
|
bash-5.2$ ls -Slah /
|
3
client/lib/goldens/testControlR-SelectMultiline-fish
Normal file
3
client/lib/goldens/testControlR-SelectMultiline-fish
Normal 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/
|
3
client/lib/goldens/testControlR-SelectMultiline-zsh
Normal file
3
client/lib/goldens/testControlR-SelectMultiline-zsh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
david@Davids-MacBook-Air hishtory % ls \
|
||||||
|
-Slah \
|
||||||
|
/
|
@ -228,7 +228,7 @@ func getRows(ctx *context.Context, columnNames []string, query string, numEntrie
|
|||||||
if strings.TrimSpace(entry.Command) == strings.TrimSpace(lastCommand) && config.FilterDuplicateCommands {
|
if strings.TrimSpace(entry.Command) == strings.TrimSpace(lastCommand) && config.FilterDuplicateCommands {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
entry.Command = strings.ReplaceAll(entry.Command, "\n", "; ")
|
entry.Command = strings.ReplaceAll(entry.Command, "\n", "\\n")
|
||||||
row, err := buildTableRow(ctx, columnNames, *entry)
|
row, err := buildTableRow(ctx, columnNames, *entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, fmt.Errorf("failed to build row for entry=%#v: %v", entry, err)
|
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
|
// Print out the initialQuery instead so that we don't clear the terminal
|
||||||
selectedRow = initialQuery
|
selectedRow = initialQuery
|
||||||
}
|
}
|
||||||
fmt.Printf("%s\n", selectedRow)
|
fmt.Printf("%s\n", strings.ReplaceAll(selectedRow, "\\n", "\n"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user