From 12ac4b86c22203be33644c5b6eccb868594f80ba Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Fri, 28 Feb 2025 16:00:41 +0100 Subject: [PATCH] veronika: add readme and scripts --- README.md | 33 +++++++++++++++++++++++++++++++++ sync.sh | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 README.md create mode 100755 sync.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..53a6a1b --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# shell-history + +## setup + + + +## zsh + +`~/.zshrc`: + +``` +HISTDB="$HOME/dev/vlv/histdb" +SHIST="$HOME/dev/vlv/shell-history" +autoload -Uz compinit promptinit add-zsh-hook + +_history() { + if test "$(id -u)" -ne 0; then + echo "$(date --utc --iso-8601=seconds) $(hostname) $(pwd) $(fc -ln -1)" >> \ + $HISTDB/zsh-history-$(date "+%Y-%m-%d").log; + fi +} +add-zsh-hook precmd _history + +_history-sync() { + if [[ -d "$HISTDB" ]]; then + () { + pushd -q "$HISTDB" + source "$SHIST/sync.sh" + popd -q + } + fi +} +``` diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..5433876 --- /dev/null +++ b/sync.sh @@ -0,0 +1,23 @@ +#!/bin/zsh + +git add zsh-history-*.log +git commit --all --message "$(hostname): update history" + +git pull --no-edit --no-rebase + +for f in ./zsh-history-*.log; do + tmpfile=$(mktemp) + exec 3>"$tmpfile" + exec 4<"$tmpfile" + rm "$tmpfile" + + grep --invert-match "^[<,>,=]\{5,\}" $f >&3 + <&4 tee $f + + sort --output="$f" "$f" + + git add $f + git commit -m "$(hostname): resolve merge ${f}" +done + +git push