title: How do I get my aliases to have correct completion?
body: <h1>Aliases that don't tab complete</h1>
  
  <p>I have a bunch of aliases like <code>j</code> for <code>jobs</code> (<a href="https://github.com/JoshCheek/dotfiles/blob/eb7e023f4a987d2b99b405bcc254bcf8c3d6ac7e/fish/functions/j.fish" rel="nofollow">here</a>), and "alias commands" like <code>gs</code> for <code>git status</code> (<a href="https://github.com/JoshCheek/dotfiles/blob/eb7e023f4a987d2b99b405bcc254bcf8c3d6ac7e/bin/gs" rel="nofollow">here</a>).</p>
  
  <p>I want them to have the tab completion of the thing they are aliasing. So <code>j -&lt;TAB&gt;</code> would complete like <code>jobs -&lt;TAB&gt;</code> and recommend --command, --pid, and so on.</p>
  
  <hr>
  
  <h2>Idea1: Extract the definition from the aliased command:</h2>
  
  <p>If there's nothing built in to tell it to treat <code>j</code> as <code>jobs</code>, then perhaps there is a way to do it dynamically? Based on <a href="https://github.com/fish-shell/fish-shell/issues/1217#issuecomment-31441757" rel="nofollow">this comment</a>and <a href="http://fishshell.com/docs/2.0/index.html#completion-own" rel="nofollow">the docs</a>, it seems like I should be able to do something like the following:</p>
  
  <pre><code>complete --command j (complete --definitions-for jobs)
  </code></pre>
  
  <p>For some made-up flag "--definitions-for", which just outputs whatever flags were put in to get the current definition (I found a function <a href="https://github.com/fish-shell/fish-shell/blob/master/complete.cpp#L2044" rel="nofollow"><code>complete_print</code></a> that's pretty close to what I want)</p>
  
  <h2>Idea2: Swap out the commandline:</h2>
  
  <p>While this might be possible for j->jobs, I started looking around and found <a href="https://github.com/fish-shell/fish-shell/blob/706286c28956e51873bfe6b673bea5be01ee7839/share/completions/git.fish#L327-334" rel="nofollow">git status completions</a>. It looks like it might be difficult (unless I can expand it before the <code>-n</code> condition is checked).</p>
  
  <p>Well, there is a <code>--do-complete</code> flag, which says "Print all completions for the specified commandline" Perhaps something along these lines:</p>
  
  <pre><code>complete -c gs --do-complete "git status -"
  </code></pre>
  
  <p>I can't actually figure out how to use --do-complete to do anything, though :/</p>