Hi ! Some ideas in bulk about bash completion, mostly about colors. Colors:
Q) how to grab them ? A) in ls.c, which parse LS_COLORS, ls --color=always Until it is implemented as a library, /bin/ls can be used. (binutils sources is the only place I found where DIR_COLORS parsing happens) Since I discovered that compgen -W can handles colorized output well, quoting is the "first" issue I can see. eg: touch "a1.mpg" "a2.tar" "b 3.mpg" "c\\4.tar" $ compgen -W "$(ls --color=always a*)" completes well with colors $ compgen -W "$(ls --color=always *)" splits "b 3.mpg" and trims the backslash of c\4.tar $ compgen -W "$(ls -b --color=always)" completes all files well with colors So now, in the script attached: - if we use the COMPREPLY n°1, we notice a problem with $IFS: (filename with space = 2 elements in COMPREPLY[]) But other than that, let's use the completion n°2 and 3: COMPREPLY=( $( compgen -W "$(ls --color=always ${cur}*)" ) ) comptest a<TAB> The line is transformed. So the next question seems to be: how to dissociate the string under the cursor from the string under the line (I used to call "suggestion") On this subject: http://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg00786.html http://groups.google.com/group/gnu.bash.bug/browse_thread/thread/532fcafba753a281/a155819450baae2f http://groups.google.com/group/gnu.bash.bug/browse_thread/thread/cc79f1be05d7318e/6493a1c2644d7e8f Chet speaking about the "visible-stats" readline variable. It makes me think that colors should really be implemented at the readline level. Perl, python or mysql shell users may really benefit from colors. http://groups.google.com/group/gnu.bash.bug/browse_thread/thread/ff22232f56f33445/72225aee50272f8d about readline hooks. Some example of what I would see offered in a flexible readline completion: - ability to display colorized filenames - ability to display option summary while <tab>ing for options list - ability to display progress bar while completing with filenames - ... maybe more IMHO: the "right way" would be: - a libdircolors which readline would link against - a colors -o option to compgen usable with -o filenames (like the inputrc/bind visible-stat) I'm quite sure it needs a patch in libreadline + at least 1 other $COMP* variable to be considered by bash + a inputrc option. This $COMPX variable may be an associative array like [word_to_complete_with] => [word_to_use_to_display_suggestion] But still it doesn't really offer the flexibility of suggestion. Or COMPREPLY_PRE(string), COMPREPLY_POST(string) and COMPREPLY_ASSOC (assoc mentioned above) ... While I'm speculating on this, I would like to speak about the ability to interrupt the completion process: Because today there are more and more completions we can not assure that all of them resolve in an acceptable time. Eg, while adding, to the cmdline, a long list of file paths, each <tab> is now considering the whole cmdline taking quite some time (some seconds with 20 files) and I ended up in using Alt+/. The same applies to emerge, apt-get, ssh, ... I still think that considering a Ctrl+g to interrupt completion is a workaround for deeper problems but this need may come sooner than we would want. As I'm throwing ideas here, I would like to know what you, bashcomp hackers, think about these subjects ? sorry for such a long oration. Raph
# bash completion for test _comptest() { local cur COMPREPLY=() _get_comp_words_by_ref cur # ex1 COMPREPLY=( $( compgen -f -- "$cur" ) ) # ex2: no completion ($cur starts with a character, wordlist elements contains shell-color-escape character) # COMPREPLY=( $( compgen -W "$(ls --color=always ${cur}*)" -- "$cur") ) # ex3: completion problem: in line $cur is replaced with the shell-color-escape character # because we omit -- $cur and the common prefix is the color # It would not complete anything if all colorized filename are of different color # COMPREPLY=( $( compgen -W "$(ls --color=always ${cur}*)") ) } && complete -F _comptest -o filenames comptest # Local variables: # mode: shell-script # sh-basic-offset: 4 # sh-indent-comment: t # indent-tabs-mode: nil # End: # ex: ts=4 sw=4 et filetype=sh
_______________________________________________ Bash-completion-devel mailing list Bash-completion-devel@lists.alioth.debian.org http://lists.alioth.debian.org/mailman/listinfo/bash-completion-devel