title: Save Zsh history to ~/.persistent_history
body: <p>Recently I want to try Z shell in Mac. But I'd like to continue also saving the command history to ~/.persistent_history, which was what I did in Bash (<a href="http://eli.thegreenplace.net/2013/06/11/keeping-persistent-history-in-bash" rel="noreferrer">ref</a>).</p>
  
  <p>However, the script in the ref link doesn't work under Zsh:</p>
  
  <pre><code>log_bash_persistent_history()
  {
     [[
       $(history 1) =~ ^\ *[0-9]+\ +([^\ ]+\ [^\ ]+)\ +(.*)$
     ]]
     local date_part="${BASH_REMATCH[1]}"
     local command_part="${BASH_REMATCH[2]}"
     if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ]
     then
       echo $date_part "|" "$command_part" &gt;&gt; ~/.persistent_history
       export PERSISTENT_HISTORY_LAST="$command_part"
     fi
  }
  run_on_prompt_command()
  {
     log_bash_persistent_history
  }
  PROMPT_COMMAND="run_on_prompt_command"
  </code></pre>
  
  <p>Is there anyone who can help me get it working? Many thanks!</p>