title: How to make bash autocomplete work in the middle of line?
body: <p>How to write autocomplete in bash, so that if I have:</p>
  
  <pre><code>mycommand first_argument|garbage
  </code></pre>
  
  <p>where <code>|</code> denotes the cursor, it should pass <code>"first_argument"</code> and not <code>"first_argumentgarbage"</code> to compgen?</p>
  
  <p>In the examples I have it behaves in the wrong way</p>
  
  <pre><code>COMPREPLY=( $(compgen -W "add remove list use current" -- "$cur") ) # buggy
  </code></pre>