I'm working on a bash completion script for a dot file management utility. The tool has a command dots diff [filename]
that will show the difference between the installed dot file and the source dot file. It also has a command dots files
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.
Here's an example of the files output
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
Using something like this
COMPREPLY=( $(compgen -W "$(dots files)" -- $cur) )
Works, however when readline lists the available options it lists out the full paths (The list above).
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.
For example, if I typed dots diff [tab][tab]
the following should be printed
X11/
bash/
bspwm/
compton/
fontconfig/
git/
gtk-2.0/
gtk-3.0/
mysql/
ncmpcpp/
pulse/
ssh/
sublime-text-3/
sxhkd/
termite/
transmission-daemon/
vim/
If for example I then typed dots diff bash/[tab][tab]
then it would show
aliases
bashrc
completion.d/
profiles/
Ideally I would like it to actually treat it as a path so that changing the readline option mark-directories
to off would exclude the trailing slashes.
I've tried setting compopt -o filenames
but this instead gives suggestions for the file names, instead of the paths initially.
bash/
it wont complete suggest any of the items under that path. I am aware that it will not work with spaces and the like, but I'm not worried about this. – Leitmotif