Bail and warn if merged histfile is a file reduction

This commit is contained in:
Sage Vaillancourt 2024-10-04 10:09:06 -04:00
parent 2424e2210f
commit bbe841e8ec
1 changed files with 7 additions and 2 deletions

View File

@ -160,8 +160,13 @@ function sync-history {
fi
echo "Merging history files..."
fc -W # Write to history file
merge-hist "$HOME/.histfile" "$HOME/.tmp/.histfile" > "$HOME/.tmp/$(whoami).histfile"
mv "$HOME/.tmp/$(whoami).histfile" "$HOME/.histfile"
local merged_name="$HOME/.tmp/$(whoami).histfile"
merge-hist "$HOME/.histfile" "$HOME/.tmp/.histfile" > "$merged_name"
if ! (($(cat "$merged_name" | wc -l) > $(cat "$HOME/.tmp/.histfile" | wc -l))); then
echo "Merged histfile '$merged_name' somehow smaller than current histfile"
return
fi
mv "$merged_name" "$HOME/.histfile"
fc -R # Read from new history file
echo "Uploading new shared history..."
tscp -P 11275 "$HOME/.histfile" 'sage@sagev.space:~/histfile'