mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-13 16:57:23 +02:00
Add basic support for stripping out HISTTIMEFORMAT prefixes
This commit is contained in:
@ -125,6 +125,7 @@ func TestParameterized(t *testing.T) {
|
||||
t.Run("testInstallViaPythonScript/"+tester.ShellName(), func(t *testing.T) { testInstallViaPythonScript(t, tester) })
|
||||
t.Run("testExportWithQuery/"+tester.ShellName(), func(t *testing.T) { testExportWithQuery(t, tester) })
|
||||
t.Run("testHelpCommand/"+tester.ShellName(), func(t *testing.T) { testHelpCommand(t, tester) })
|
||||
t.Run("testStripBashTimePrefix/"+tester.ShellName(), func(t *testing.T) { testStripBashTimePrefix(t, tester) })
|
||||
}
|
||||
}
|
||||
|
||||
@ -1142,4 +1143,64 @@ func testHelpCommand(t *testing.T, tester shellTester) {
|
||||
}
|
||||
}
|
||||
|
||||
func testStripBashTimePrefix(t *testing.T, tester shellTester) {
|
||||
if tester.ShellName() != "bash" {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
// Setup
|
||||
defer shared.BackupAndRestore(t)()
|
||||
installHishtory(t, tester, "")
|
||||
|
||||
// Add a HISTTIMEFORMAT to the bashrc
|
||||
homedir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f, err := os.OpenFile(path.Join(homedir, ".hishtory", "config.sh"),
|
||||
os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.WriteString("\nexport HISTTIMEFORMAT='%F %T '\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Record a command
|
||||
tester.RunInteractiveShell(t, `ls -Slah`)
|
||||
|
||||
// Check it shows up correctly
|
||||
out := tester.RunInteractiveShell(t, "hishtory export ls")
|
||||
if out != "ls -Slah\n" {
|
||||
t.Fatalf("hishtory had unexpected output=%#v", out)
|
||||
}
|
||||
|
||||
// Update it to another complex one
|
||||
homedir, err = os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f, err = os.OpenFile(path.Join(homedir, ".hishtory", "config.sh"),
|
||||
os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.WriteString("\nexport HISTTIMEFORMAT='[%c] '\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Record a command
|
||||
tester.RunInteractiveShell(t, `echo foo`)
|
||||
|
||||
// Check it shows up correctly
|
||||
out = tester.RunInteractiveShell(t, "hishtory export echo")
|
||||
if out != "echo foo\n" {
|
||||
t.Fatalf("hishtory had unexpected output=%#v", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: write a test that runs hishtroy export | grep -v pipefail and then see if that shows up in query/export, I think there is weird behavior here
|
||||
|
Reference in New Issue
Block a user