From 996ab9a5dc35729b804046639d851081987dc14f Mon Sep 17 00:00:00 2001 From: tdro Date: Tue, 5 Jul 2022 06:24:26 -0400 Subject: .local/bin/bashhistory: Add lock file --- .local/bin/bashhistory | 9 +++++++-- 1 file 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 -- cgit v1.2.3