aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authortdro <tdro@users.noreply.github.com>2022-03-18 13:58:56 -0400
committertdro <tdro@users.noreply.github.com>2022-03-18 14:05:43 -0400
commitd60564519cb4fab19dbf270dd7696052990fcfe1 (patch)
treee5b71478284050f5ad3715d6561f2dba78f11902 /.local
parentd8f916b6fe986a2974620d4386ec50de08f9d938 (diff)
downloaddotfiles-d60564519cb4fab19dbf270dd7696052990fcfe1.tar.gz
dotfiles-d60564519cb4fab19dbf270dd7696052990fcfe1.tar.bz2
dotfiles-d60564519cb4fab19dbf270dd7696052990fcfe1.zip
.bash_profile: Fix history with real persist
Use custom fzf completion and bindings.
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/bashhistory31
1 files changed, 31 insertions, 0 deletions
diff --git a/.local/bin/bashhistory b/.local/bin/bashhistory
new file mode 100755
index 0000000..6320834
--- /dev/null
+++ b/.local/bin/bashhistory
@@ -0,0 +1,31 @@
+#!/bin/sh -eu
+
+directory="$XDG_DATA_HOME/bash"
+persist="$directory/history"
+default="$HOME/.bash_history"
+current="$HISTFILE"
+
+_prune() {
+ sed --in-place '/^#/d' "$1" && # Remove all timestamps.
+ sed --in-place '/......../!d' "$1" && # Remove all commands 8 characters or less.
+ sort --unique "$1" | sponge "$1" # Remove all duplicate entries.
+}
+
+mkdir --parents "$directory"
+touch "$current"
+
+_migrate() {
+ [ -f "$default" ] &&
+ cat "$default" >>"$persist" &&
+ _prune "$persist" &&
+ rm "$default"
+}
+
+_store() {
+ cat "$current" >> "$persist" &&
+ _prune "$persist" &&
+ true > "$current"
+}
+
+_migrate || true
+_store