diff --git a/fake_home/.zshrc b/fake_home/.zshrc index 744ea78..18c33c5 100644 --- a/fake_home/.zshrc +++ b/fake_home/.zshrc @@ -152,24 +152,28 @@ function merge-hist { } function sync-history { + local local_history="$HOME/.histfile" + local remote_file="sage@sagev.space:~/histfile" + local copy_of_remote="$HOME/.tmp/.histfile" + local merged="$HOME/.tmp/$(whoami).histfile" + echo "Downloading shared history..." - if ! tscp -P 11275 'sage@sagev.space:~/histfile' "$HOME/.tmp/.histfile"; then + if ! tscp -P 11275 "$remote_file" "$copy_of_remote"; then echo "Shared history download failed!" - tscp -P 11275 "$HOME/.histfile" 'sage@sagev.space:~/histfile' + tscp -P 11275 "$local_history" "$remote_file" return fi echo "Merging history files..." fc -W # Write to history file - 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" + merge-hist "$local_history" "$copy_of_remote" > "$merged" + if ! (($(cat "$merged" | wc -l) > $(cat "$copy_of_remote" | wc -l))); then + echo "Merged histfile '$merged' somehow smaller than current histfile" return fi - mv "$merged_name" "$HOME/.histfile" + mv "$merged" "$local_history" fc -R # Read from new history file echo "Uploading new shared history..." - tscp -P 11275 "$HOME/.histfile" 'sage@sagev.space:~/histfile' + tscp -P 11275 "$local_history" "$remote_file" } function install-extension {