From 16055f982ef0f9c683d79c398ba50f21dd66ecb9 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 17 Apr 2022 21:04:44 -0700 Subject: [PATCH] Skip commands prefixed with a space for zsh + update tests + touch ~/.zshrc so tests can run on actions --- .github/workflows/go-test.yml | 1 + client/client_test.go | 10 +++------- client/lib/lib.go | 11 ++++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index d1739aa..c74cd87 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -20,4 +20,5 @@ jobs: if: ${{ !startsWith(github.event.head_commit.message, 'Release') }} run: | sudo apt-get install -y zsh || true + touch ~/.zshrc make test diff --git a/client/client_test.go b/client/client_test.go index a316797..2e7d08a 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -674,10 +674,6 @@ hishtory enable`, i)) } func testExcludeHiddenCommand(t *testing.T, tester shellTester) { - if tester.ShellName() == "zsh" { - t.Skip() - // TODO - } // Set up defer shared.BackupAndRestore(t)() installHishtory(t, tester, "") @@ -687,8 +683,8 @@ func testExcludeHiddenCommand(t *testing.T, tester shellTester) { echo hello2 echo hidden`) tester.RunInteractiveShell(t, " echo hidden") - out := hishtoryQuery(t, tester, "") - if strings.Count(out, "\n") != 5 && strings.Count(out, "\n") != 6 { + out := hishtoryQuery(t, tester, "-pipefail") + if strings.Count(out, "\n") != 3 { t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out) } if strings.Count(out, "echo hello") != 2 { @@ -705,7 +701,7 @@ echo hello2 } out = tester.RunInteractiveShell(t, "hishtory export | grep -v pipefail | grep -v '/tmp/client install'") - expectedOutput := "echo hello1\necho hello2\nhishtory query\n" + expectedOutput := "echo hello1\necho hello2\n" if out != expectedOutput { t.Fatalf("hishtory export has unexpected output=%#v", out) } diff --git a/client/lib/lib.go b/client/lib/lib.go index 2c25d3d..9023389 100644 --- a/client/lib/lib.go +++ b/client/lib/lib.go @@ -108,16 +108,17 @@ func BuildHistoryEntry(args []string) (*data.HistoryEntry, error) { return nil, fmt.Errorf("failed to check if command was hidden: %v", err) } if shouldBeSkipped { - return nil, nil - } - if strings.HasPrefix(cmd, " ") { // Don't save commands that start with a space return nil, nil } entry.Command = cmd } else if shell == "zsh" { - // TODO: skip commands that start with a space - entry.Command = strings.TrimSpace(args[4]) + cmd := strings.TrimSuffix(strings.TrimSuffix(args[4], "\n"), " ") + if strings.HasPrefix(cmd, " ") { + // Don't save commands that start with a space + return nil, nil + } + entry.Command = cmd } else { return nil, fmt.Errorf("tried to save a hishtory entry from an unsupported shell=%#v", shell) }