Created
July 13, 2023 09:53
-
-
Save snowman11784/e6cb616359e1b4d056a35d8f489f8449 to your computer and use it in GitHub Desktop.
Remove history entries in bulk
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
#!/usr/bin/env bash | |
################################# | |
# Remove history entries in bulk | |
################################# | |
run() { | |
echo "$@" | |
if [[ ! $DRY_RUN == true ]]; then | |
"$@" | |
fi | |
} | |
rmhist() { | |
local lines=($1) | |
history -r | |
for line in "${lines[@]}"; do | |
run history -d $line | |
if [[ $? -eq 0 ]]; then | |
run history -w | |
else | |
echo "history deletion failed for $line" | |
continue | |
fi | |
done | |
} | |
DEBUG=0 | |
VERBOSE=0 | |
unset OPTIND | |
unset OPTARG | |
while getopts "dhv" opt; do | |
case "${opt}" in | |
d) | |
DRY_RUN=true | |
DEBUG=1 | |
;; | |
h) | |
usage | |
exit 1 | |
;; | |
v) | |
set -x | |
VERBOSE=1 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
HISTFILE=~/.bash_history | |
rmhist "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment