Last active
January 17, 2024 18:13
-
-
Save mrcnski/f66b99eb202b94f3143fbea1b0f07f87 to your computer and use it in GitHub Desktop.
Clean Bash History
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Cleans up garbage lines and duplicate entries. | |
# | |
# DEPENDENCIES: | |
# | |
# - rg: cargo install ripgrep | |
# - unique: go install github.com/ro-tex/unique@latest | |
# - sponge: brew install moreutils | |
# | |
# INSTALLATION: | |
# | |
# - Makefile entry: | |
# | |
# clean-history: | |
# ./clean-history.sh "${HOME}/.zsh_history" | |
# | |
# - crontab entry: | |
# | |
# */2 * * * * source $HOME/.profile && /usr/bin/make -C $HOME/Home/ clean-history | |
# | |
# NOTE: | |
# | |
# - When cleaning duplicate entries the most recent one is kept, to preserve | |
# order when searching backwards. | |
# - This breaks in `make` due to the `#`, hence the stand-alone script. | |
# - Using `>` would clear the output file first, hence the `sponge`s. | |
FILE=$1 | |
tail -r "$FILE" | unique -t | rg -v '^\#' | tail -r | sponge "$FILE" |
I'm so happy you find it useful!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks again @ro-tex!
unique
had appeared in my GitHub feed exactly when I needed it. 👀