BashScripts.org
http://bashscripts.org/forum/

Handling wordbreaks in bash completion
http://bashscripts.org/forum/viewtopic.php?f=16&t=996
Page 1 of 1

Author:  azrael [ Tue Feb 16, 2010 11:01 am ]
Post subject:  Handling wordbreaks in bash completion

Hello, people.

I am writing completion function for one PHP framework called symfony.
It has command line interface with syntax:

Code:
symfony [options] [namespace:]action


I want to make action be autocompletable.
The function is simplest so far:

Code:
function _symfony_commands()
{
   [ -r "cache/completion/.sf" ] && cat cache/completion/.sf
}

function _symfony
{
    COMPREPLY=( $( compgen -W "$(_symfony_commands)" -- ${COMP_WORDS[COMP_CWORD]} ) )
}

complete -F _symfony symfony


In the .sf file placed list of all available commands divided by space.
And it works fine if there is no namespace in symfony action, e.g.:

symfony he[TAB]
will be properly completed to
symfony help

But, if there is : symbol which separate namespace from action problems coming:
symfony doct[TAB]
will be completed to
symfony doctrine:

But nothing happens if you want complete after : symbol.
I've found out that for readline there is three words because it splits line with $COMP_WORDBREAKS

Code:
$ echo $COMP_WORDBREAKS
"'><=;|&(:


I played with $COMP_WORDS array and tried every thought I had to make it work, but failed.
What I should do to escape colon and make readline consider it as one word?
Or there is way perhaps to workaround it?

Any help are appreciated.

Contents of cache/completion/.sf (the board engine doesn't allow upload .txt for some reason)
Code:
cc help init-controller list log:clear log:rotate plugin:add-channel plugin:install plugin:list plugin:package plugin:publish-assets plugin:uninstall plugin:upgrade project:clear-controllers project:deploy project:disable project:enable project:optimize project:permissions project:send-emails project:validate subversion:set-props symfony:test sympal:build-search-index sympal:configure sympal:create-site sympal:delete-site sympal:disable-for-app sympal:enable-for-app sympal:event-list sympal:fix-perms sympal:import-content sympal:install sympal:plugin-download sympal:plugin-generate sympal:plugin-install sympal:plugin-list sympal:plugin-uninstall sympal:purge-content sympal:redirect-route sympal:report-statistics sympal:server-check sympal:upgrade sympal:version test:all test:coverage test:functional test:plugin test:unit

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com