title: Writing __fish_is_first_arg, but includes the arg's parameter
body: <p>I'm writing a completions file for <a href="https://developers.google.com/speed/webp/docs/cwebp" rel="nofollow noreferrer">cwebp</a>, Google's to-webp converter. Its help says that <code>-preset</code> should come before all other arguments. With that in mind, I tried restricting its availability with <code>__fish_is_first_arg</code>, like this:</p>
  
  <pre><code>complete -c cwebp -x -n '__fish_is_first_arg' -o preset -a 'default photo picture drawing icon text' -d 'Preset setting'
  </code></pre>
  
  <p>This would make it so <code>cwebp -o -pres&lt;Tab&gt;</code> would <em>not</em> suggest <code>-preset</code>, which is what I wanted.</p>
  
  <p>Meanwhile, <code>cwebp -pres&lt;Tab&gt;</code> would fill out the argument to its full <code>-preset</code>, which is also what I wanted.</p>
  
  <p>However, when I press the Tab key at <code>cwebp -preset &lt;Tab&gt;</code>, the only suggestions given are the files and directories in the current directory. This is not what I wanted.</p>
  
  <hr>
  
  <p>With this in mind, I figured I had to write a "is first or second option" function. However, it's not going well. Here's what I have so far:</p>
  
  <pre><code>function __fish_cwebp_is_first_option_or_its_argument
      set -l tokens (commandline -co)
      # line alpha
      switch (count tokens)
          case 1
              return 0
          case 2
              if test \( "$tokens[2]" = '-preset' \)
                  return 0
              end
              return 1
          case '*'
              # line beta
              breakpoint
              return 1
      end
  end
  </code></pre>
  
  <p>This function body, as far as I can tell, works the same way as <code>return 0</code> (<code>(true)</code>). No matter what, <code>-pres&lt;Tab&gt;</code> completes to <code>-preset</code>, even when the line looks like <code>cwebp -h -H -version -pres&lt;Tab&gt;</code>.</p>
  
  <p>When I put a breakpoint on line alpha, I can <code>echo $tokens</code> and see all the tokens that I've totally typed out (there needs to be at least one space between the last token and the cursor). However, when I have only a breakpoint on line beta as shown here, I can't even get the breakpoint to trigger. Not even with <code>cwebp -h -H -version -pres&lt;Tab&gt;</code> as mentioned above.</p>
  
  <p>What am I doing wrong?</p>