shell-history/sync.sh

34 lines
682 B
Bash
Executable file

#!/bin/zsh
histdb="$1"
shift
if [[ -d "$histdb" ]]; then
pushd -q "$histdb"
git add zsh-history-*.log .gitattributes 2>/dev/null
git diff --cached --quiet || git commit -m "$(hostname): update history"
git pull --no-edit --no-rebase
needs_commit=false
for f in ./zsh-history-*.log; do
[[ -f "$f" ]] || continue
if ! sort -c "$f" 2>/dev/null; then
sort -o "$f" "$f"
needs_commit=true
fi
done
if $needs_commit; then
git add zsh-history-*.log
git commit -m "$(hostname): sort after merge"
fi
git push
popd -q
else
echo "\$histdb does not exist at: \"$histdb\" "
fi