aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@users.noreply.github.com>2022-07-05 06:24:26 -0400
committertdro <tdro@users.noreply.github.com>2022-07-05 06:24:26 -0400
commit996ab9a5dc35729b804046639d851081987dc14f (patch)
treed1a50fcf2a280bfe3eda82d9c92b753a51b01086
parent37ed2cbaf7a321c2fa8a0e14d460907ee2db41c6 (diff)
downloaddotfiles-996ab9a5dc35729b804046639d851081987dc14f.tar.gz
dotfiles-996ab9a5dc35729b804046639d851081987dc14f.tar.bz2
dotfiles-996ab9a5dc35729b804046639d851081987dc14f.zip
.local/bin/bashhistory: Add lock file
-rwxr-xr-x.local/bin/bashhistory9
1 files changed, 7 insertions, 2 deletions
diff --git a/.local/bin/bashhistory b/.local/bin/bashhistory
index 47eb762..bfaa122 100755
--- a/.local/bin/bashhistory
+++ b/.local/bin/bashhistory
@@ -4,10 +4,11 @@ directory="$XDG_DATA_HOME/bash"
persist="$directory/history"
default="$HOME/.bash_history"
current="$HISTFILE"
+lockfile='/tmp/bashhistory_Ri5ki9ei.lock'
_prune() {
sed --in-place '/^#/d' "$1" && # Remove all timestamps.
- sed --in-place '/......../!d' "$1" && # Remove all commands 8 characters or less.
+ sed --in-place '/.........../!d' "$1" && # Remove all commands less than 11 characters.
sort --unique "$1" | sponge "$1" # Remove all duplicate entries.
}
@@ -25,8 +26,12 @@ _store() {
true > "$current"
}
+[ -f "$lockfile" ] && exit;
+
mkdir --parents "$directory"
-touch "$current"
+touch "$current" "$lockfile"
+
+trap 'rm "$lockfile"; trap - EXIT; exit' EXIT INT HUP
_migrate || true
_store