From 0db27d42177c60bebafadff7aa4aa412abc9cc12 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 24 Sep 2023 16:35:00 -0700 Subject: [PATCH] Add workaround for bash issues with pre-saving --- client/cmd/saveHistoryEntry.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/cmd/saveHistoryEntry.go b/client/cmd/saveHistoryEntry.go index 90dfe6c..1f8d3ea 100644 --- a/client/cmd/saveHistoryEntry.go +++ b/client/cmd/saveHistoryEntry.go @@ -154,8 +154,14 @@ func presaveHistoryEntry(ctx context.Context) { entry.StartTime = time.Unix(startTime, 0).UTC() entry.EndTime = time.Unix(0, 0).UTC() - // Skip saving references to presaving - if strings.Contains(entry.Command, "presaveHistoryEntry") || strings.Contains(entry.Command, "__history_control_r") { + // Shell workaround: Pre-saving on bash relies on the $BASH_COMMAND variable which also will get set/executed + // when running shell scripts/functions, but saveHistoryEntry will never be invoked for those entries. + // This leads to problems where the history gets filled with some bogus pre-saved entries from shell + // scripts or .bashrc files. Attempt to workaround this by filtering out certain patterns that are + // especially likely to fall into this. + // TODO: Try to improve this ^ + shellName := os.Args[2] + if shellName == "bash" && (strings.Contains(entry.Command, "presaveHistoryEntry") || strings.HasPrefix(entry.Command, "_")) { return }