Paver bash auto complete

143 views
Skip to first unread message

Rohit

unread,
Jan 20, 2010, 6:20:36 AM1/20/10
to paver
Hi,
I think having a paver bash auto complete which lists all the tasks
would be extremely useful. I got the inspiration after looking at
virtualenvwrapper. I put the following code in my .bashrc:

_paver()
{
cmds=`paver -q list_tasks`
COMPREPLY=( $(compgen -W '$cmds' -- $cur))
}
complete -F _paver paver

This bash script assumes that the pavement file being used is the
default one ie pavement.py and that file has a task called
'list_tasks' which lists all the task. If 'list_tasks' task could be
merged into paver package itself, that would be really useful.

Now whenever I am in my python project directory with a pavement.py
which has the necessary 'list_tasks' method, I have auto-complete with
paver!

My two pence.

Kevin Dangoor

unread,
Jan 20, 2010, 8:08:13 AM1/20/10
to pa...@googlegroups.com
Hi Rohit,

Yes, this would be handy. I was thinking that the other day. What does list_tasks look like?

--
You received this message because you are subscribed to the Google Groups "paver" group.
To post to this group, send email to pa...@googlegroups.com.
To unsubscribe from this group, send email to paver+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/paver?hl=en.






--
Kevin Dangoor

work: http://labs.mozilla.com/
email: k...@blazingthings.com
blog: http://www.BlueSkyOnMars.com

Rohit

unread,
Jan 20, 2010, 10:50:41 AM1/20/10
to paver
The 'list_tasks' method looks like:

@task
def list_tasks():
task_list = environment.get_tasks()
for task in task_list:
print task.shortname

I copied this bit of code from a method called 'help' in paver/
tasks.py.

Note that my script suppresses all other auto completion. So its
definitely just an idea right now.

cheers

> > paver+un...@googlegroups.com <paver%2Bunsu...@googlegroups.com>.

Message has been deleted

jhermann

unread,
Dec 17, 2010, 6:49:08 AM12/17/10
to pa...@googlegroups.com
This works without special requirements towards the pavement:

_paver()
{
    cmds=$(paver help tasks | egrep "^ .+ - " | sed -re 's/\s+(.*?)\s+-\s.*$/\1/' | grep -v ^_)

    COMPREPLY=( $(compgen -W '$cmds' -- "$cur") )
}
complete -F _paver paver

It also excludes tasks beginning with _ (i.e. "private" ones).

Luca Invernizzi

unread,
Oct 3, 2011, 1:04:40 PM10/3/11
to pa...@googlegroups.com
Paver bash autocompletion, without the need of a special "list_tasks"
task
and filtering tasks starting with _


_paver()
{
cmds=$( paver -hq | awk '/\s*([a-zA-Z][a-zA-Z0-9_]+)/
{print $1}' )


COMPREPLY=( $(compgen -W '$cmds' -- "$cur") )
}

complete -F _paver paver

Gregory Nicholas

unread,
Dec 28, 2012, 3:57:39 PM12/28/12
to pa...@googlegroups.com
i'm a couple years too late.. but this works well, as it removes the autocomplete for flag options:

_paver()
{
    local cur
    COMPREPLY=()
    # Variable to hold the current word
    cur="${COMP_WORDS[COMP_CWORD]}"

    # Build a list of the available tasks from: `paver --help --quiet`
    local cmds=$(paver -hq | awk '/^  ([a-zA-Z][a-zA-Z0-9_]+)/ {print $1}')

    # Generate possible matches and store them in the
    # array variable COMPREPLY
    COMPREPLY=($(compgen -W "${cmds}" $cur))
}

# Assign the auto-completion function for our command.
complete -F _paver paver
Reply all
Reply to author
Forward
0 new messages