diff --git a/history-sync.plugin.zsh b/history-sync.plugin.zsh index 00bc417..8823b7a 100644 --- a/history-sync.plugin.zsh +++ b/history-sync.plugin.zsh @@ -27,6 +27,7 @@ ZSH_HISTORY_FILE="${ZSH_HISTORY_FILE:-${HOME}/${ZSH_HISTORY_FILE_NAME}}" ZSH_HISTORY_FILE_ENC_NAME="${ZSH_HISTORY_FILE_ENC_NAME:-zsh_history}" ZSH_HISTORY_FILE_ENC="${ZSH_HISTORY_FILE_ENC:-${ZSH_HISTORY_PROJ}/${ZSH_HISTORY_FILE_ENC_NAME}}" ZSH_HISTORY_FILE_DECRYPT_NAME="${ZSH_HISTORY_FILE_DECRYPT_NAME:-zsh_history_decrypted}" +ZSH_HISTORY_FILE_MERGED_NAME="${ZSH_HISTORY_FILE_MERGED_NAME:-zsh_history_merged}" ZSH_HISTORY_COMMIT_MSG="${ZSH_HISTORY_COMMIT_MSG:-latest $(date)}" function _print_git_error_msg() { @@ -159,13 +160,15 @@ function history_sync_pull() { [[ -o extendedhistory ]] && _squash_multiline_commands_in_files # Merge - cat "$ZSH_HISTORY_FILE" "$ZSH_HISTORY_FILE_DECRYPT_NAME" | awk '/:[0-9]/ { if(s) { print s } s=$0 } !/:[0-9]/ { s=s"\n"$0 } END { print s }' | LC_ALL=C sort -u > "$ZSH_HISTORY_FILE" + cat "$ZSH_HISTORY_FILE" "$ZSH_HISTORY_FILE_DECRYPT_NAME" | awk '/:[0-9]/ { if(s) { print s } s=$0 } !/:[0-9]/ { s=s"\n"$0 } END { print s }' | LC_ALL=C sort -u > "$ZSH_HISTORY_FILE_MERGED_NAME" + mv "$ZSH_HISTORY_FILE_MERGED_NAME" "$ZSH_HISTORY_FILE" rm "$ZSH_HISTORY_FILE_DECRYPT_NAME" cd "$DIR" # Check if EXTENDED_HISTORY is enabled, and if so, restore multi-line # commands in the local history file [[ -o extendedhistory ]] && _restore_multiline_commands_in_file + sed -i '/^$/d' "$ZSH_HISTORY_FILE" } # Encrypt and push current history to master