Clarify sync-history
This commit is contained in:
parent
260e3a4749
commit
66cf733f4e
|
@ -152,24 +152,28 @@ function merge-hist {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sync-history {
|
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..."
|
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!"
|
echo "Shared history download failed!"
|
||||||
tscp -P 11275 "$HOME/.histfile" 'sage@sagev.space:~/histfile'
|
tscp -P 11275 "$local_history" "$remote_file"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
echo "Merging history files..."
|
echo "Merging history files..."
|
||||||
fc -W # Write to history file
|
fc -W # Write to history file
|
||||||
local merged_name="$HOME/.tmp/$(whoami).histfile"
|
merge-hist "$local_history" "$copy_of_remote" > "$merged"
|
||||||
merge-hist "$HOME/.histfile" "$HOME/.tmp/.histfile" > "$merged_name"
|
if ! (($(cat "$merged" | wc -l) > $(cat "$copy_of_remote" | wc -l))); then
|
||||||
if ! (($(cat "$merged_name" | wc -l) > $(cat "$HOME/.tmp/.histfile" | wc -l))); then
|
echo "Merged histfile '$merged' somehow smaller than current histfile"
|
||||||
echo "Merged histfile '$merged_name' somehow smaller than current histfile"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
mv "$merged_name" "$HOME/.histfile"
|
mv "$merged" "$local_history"
|
||||||
fc -R # Read from new history file
|
fc -R # Read from new history file
|
||||||
echo "Uploading new shared history..."
|
echo "Uploading new shared history..."
|
||||||
tscp -P 11275 "$HOME/.histfile" 'sage@sagev.space:~/histfile'
|
tscp -P 11275 "$local_history" "$remote_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
function install-extension {
|
function install-extension {
|
||||||
|
|
Loading…
Reference in New Issue