title: Bash completion function: limit matches via glob
body: <p>A Bash completion function that uses <code>compgen</code> can work with the current partially-complete word. How can I restrict matches to those which match a specific file glob?</p>
  
  <p>The <code>-G 'fooglob'</code> option does not do this; it <em>ignores</em> the current word and just unconditionally matches the glob.</p>
  
  <p>What I want is:</p>
  
  <pre class="lang-bash prettyprint-override"><code>compgen -A file -FOO '*.yaml' -- "$cur"
  </code></pre>
  
  <p>and have the generated options only those that match <em>both</em> the current word <em>and</em> the specified glob. So what is that hypothetical <code>-FOO</code> option?</p>
  
  <p>(Note that this is a question specifically about writing functions in the Bash programming language, which is why it's appropriate on StackOverflow.)</p>