title: Bash completion: compgen a wordlist as if they were paths - Only suggest up until next slash
body: <p>I'm working on a bash completion script for a <a href="https://github.com/EvanPurkhiser/dot-config/blob/custom-env-dotfiles/dots" rel="noreferrer">dot file management utility</a>. The tool has a command <code>dots diff [filename]</code> that will show the difference between the installed dot file and the source dot file. It also has a command <code>dots files</code> which lists the paths of all managed dot files (relative to the source directory). I would like to complete the diff command with the output of the files command.</p>
  
  <p>Here's an example of the files output</p>
  
  <pre><code>X11/xkb/symbols/evan-custom
  X11/xorg.conf.d/10-dual-monitors.conf
  X11/xorg.conf.d/10-keylayout.conf
  bash/aliases
  bash/bashrc
  bash/completion.d/dots
  bash/profiles/standard-user
  bash/profiles/systemd-user
  bspwm/bspwmrc
  compton/compton.conf
  fontconfig/fonts.conf
  git/config
  git/ignore
  gtk-2.0/gtkrc
  gtk-3.0/settings.ini
  mysql/config
  mysql/grcat
  ncmpcpp/config
  pulse/client.conf
  pulse/daemon.conf
  pulse/default.pa
  ssh/config
  sublime-text-3/Packages/User/Preferences.sublime-settings
  sxhkd/sxhkdrc
  termite/config
  transmission-daemon/settings.json
  vim/vimrc
  </code></pre>
  
  <p>Using something like this</p>
  
  <pre><code>COMPREPLY=( $(compgen -W "$(dots files)" -- $cur) )
  </code></pre>
  
  <p>Works, however when readline lists the available options it lists out the full paths (The list above).</p>
  
  <p>I would like for it to treat the words as if they were file paths and when listing suggestions only list up to the first forward slash.</p>
  
  <p>For example, if I typed <code>dots diff [tab][tab]</code> the following should be printed</p>
  
  <pre><code>X11/
  bash/
  bspwm/
  compton/
  fontconfig/
  git/
  gtk-2.0/
  gtk-3.0/
  mysql/
  ncmpcpp/
  pulse/
  ssh/
  sublime-text-3/
  sxhkd/
  termite/
  transmission-daemon/
  vim/
  </code></pre>
  
  <p>If for example I then typed <code>dots diff bash/[tab][tab]</code> then it would show</p>
  
  <pre><code>aliases
  bashrc
  completion.d/
  profiles/
  </code></pre>
  
  <p>Ideally I would like it to <em>actually treat it as a path</em> so that changing the readline option <code>mark-directories</code> to off would exclude the trailing slashes.</p>
  
  <p>I've tried setting <code>compopt -o filenames</code> but this instead gives suggestions for the file names, instead of the paths initially.</p>
  
  <p><a href="https://gist.github.com/EvanPurkhiser/7294574" rel="noreferrer">Here is the completion script I have so far</a></p>