Add config option to filter out duplicate history entries as requested in #10

This commit is contained in:
David Dworken
2022-11-03 20:36:36 -07:00
parent 83ca625ad9
commit 6dea8a989e
12 changed files with 162 additions and 8 deletions

View File

@ -2069,6 +2069,38 @@ echo bar`)
}
}
func TestRemoveDuplicateRows(t *testing.T) {
// Setup
tester := bashTester{}
defer testutils.BackupAndRestore(t)()
installHishtory(t, tester, "")
// Record a few commands and check that they get recorded and all are displayed in a table
tester.RunInteractiveShell(t, `echo foo
echo foo
echo baz
echo baz
echo foo`)
out := tester.RunInteractiveShell(t, `hishtory export -pipefail`)
compareGoldens(t, out, "testRemoveDuplicateRows-export")
tester.RunInteractiveShell(t, `hishtory config-set displayed-columns 'Exit Code' Command`)
out = tester.RunInteractiveShell(t, `hishtory query -pipefail`)
compareGoldens(t, out, "testRemoveDuplicateRows-query")
out = captureTerminalOutput(t, tester, []string{"hishtory SPACE tquery SPACE -pipefail ENTER"})
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
compareGoldens(t, out, "testRemoveDuplicateRows-tquery")
// And change the config to filter out duplicate rows
tester.RunInteractiveShell(t, `hishtory config-set filter-duplicate-commands true`)
out = tester.RunInteractiveShell(t, `hishtory export -pipefail`)
compareGoldens(t, out, "testRemoveDuplicateRows-enabled-export")
out = tester.RunInteractiveShell(t, `hishtory query -pipefail`)
compareGoldens(t, out, "testRemoveDuplicateRows-enabled-query")
out = captureTerminalOutput(t, tester, []string{"hishtory SPACE tquery SPACE -pipefail ENTER"})
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
compareGoldens(t, out, "testRemoveDuplicateRows-enabled-tquery")
}
type deviceSet struct {
deviceMap *map[device]deviceOp
currentDevice *device