veronika: add readme and scripts

This commit is contained in:
Viktor Varland 2025-02-28 16:00:41 +01:00
commit 12ac4b86c2
Signed by: varl
GPG key ID: 7459F0B410115EE8
2 changed files with 56 additions and 0 deletions

33
README.md Normal file
View file

@ -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
}
```

23
sync.sh Executable file
View file

@ -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