It is currently Fri May 25, 2018 8:56 am

Handling wordbreaks in bash completion

All times are UTC - 6 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Tue Feb 16, 2010 11:01 am   

Joined: Tue Feb 16, 2010 10:34 am
Posts: 1
Hello, people.

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

symfony [options] [namespace:]action

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

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


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)
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

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Google [Bot] and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group