title: zshaddhistory(): Must override (to store CWD), but the standard ways break !$
body: <p>I use <code>!$</code> a <em>lot</em>. <code>cat some-long-file</code>. Then I want to edit it. Must use <code>!$</code>: <code>vim !$</code></p>
  
  <p>Now with a definition that is like this: </p>
  
  <pre><code>zshaddhistory () {
     print -sr "${1%%$'\n'}"
     # some other stuff
     fc -p
  }
  </code></pre>
  
  <p>It all mostly seems to work at first (for a few weeks I thought I was good to go), but it quickly became clear that <code>!$</code> was not working properly any longer.</p>
  
  <p>I look over <code>man zshbuiltins</code> at <code>fc</code> and <code>print</code>. </p>
  
  <p>But none of it makes enough sense for me to understand just what this <code>print -sr</code> <code>fc -p</code> madness is. </p>
  
  <p>It appears that <code>"${1%%$'\n'}"</code> simply does not do the same thing as the default <code>zsh</code> behavior. It saves it in such a way that <code>!$</code> (or e.g. <code>!-5$</code>) will NOT retrieve the last arg, it retrieves the <strong>entire</strong> command.</p>
  
  <p>What can I do? I've tried taking out the double-quotes, so <code>$1</code> gets expanded out. But it still isn't being fully expanded out. Hopefully someone knows exactly what the problem is. </p>
  
  <p>Maybe <code>print -sr</code> is simply the wrong command.</p>