2

I am working on a script called to that bookmarks file system locations in bash (with limited support for zsh). You can find the source here: https://github.com/resultsreturned/to

The script supports tab completion for all operations.

Say you have "bookmarked" the location of a folder:

mara@andromeda:~/bin/android-sdk-linux$ to -b android

The script then allows you to access subfolders of the bookmark, like so:

mara@andromeda:~$ to android/docs/
mara@andromeda:~/bin/android-sdk-linux/docs$ 

Pressing tab twice will give suggestions:

mara@andromeda:~$ to android/s<TAB><TAB>
android/samples/        android/sd-card/        android/sources/        android/system-images/  

However, I would rather that the suggestions print only the portion of the path that is not currently input into the buffer. For example, the cd command:

mara@andromeda:~/bin$ cd android-sdk-linux/s<TAB><TAB>
samples/       sd-card/       sources/       system-images/ 

Note how the suggestions only contain the directory level that is currently being input.

So the question is, how do you control the way bash prints suggestions? Is it possible to do this independently of the completion wordlist (for compgen/complete)? Is there some way to define a regex that would process the completion wordlist for printing as suggestions?

  • So the solution turns out to be using `-o filenames` when invoking `complete`. http://stackoverflow.com/questions/3951628/showing-only-the-substrings-of-compreply-bash-completion-options-to-the-user – resultsreturned Feb 18 '13 at 00:55

1 Answers1

1

Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.

So the solution turns out to be using -o filenames when invoking complete. Showing only the substrings of COMPREPLY bash completion options to the user – resultsreturned

Community
  • 1
  • 1
Armali
  • 18,255
  • 14
  • 57
  • 171