From 55238de72a3e0fe96e6d371b6e32740dcb896b62 Mon Sep 17 00:00:00 2001
From: Andres Montano <andres.montano@tecnalia.com>
Date: Wed, 6 Nov 2024 11:20:20 +0100
Subject: [PATCH] Add script to clean history

---
 dockerfiles/scripts/clean_history.bash | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 dockerfiles/scripts/clean_history.bash

diff --git a/dockerfiles/scripts/clean_history.bash b/dockerfiles/scripts/clean_history.bash
new file mode 100644
index 0000000..ae1769f
--- /dev/null
+++ b/dockerfiles/scripts/clean_history.bash
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+sed ':start; /\\$/ { N; s/\\\n/\\\x00/; b start }' .zsh_history  # join multiline commands
+| nl -nrz                  # add line numbers so we can restore the original order
+| tac | sort -t';' -u -k2  # sort and remove duplicate commands, keeping the last occurrence
+| sort                     # sort on line numbers
+| cut -d$'\t' -f2-         # remove the line numbers
+| tr '\000' '\n'           # restore multiline commands
+> .zsh_history_deduped
\ No newline at end of file
-- 
GitLab