[Ann] rpa bash programable completion

B

Brian Schröder

I hacked together a bash completion file for rpa, and wanted to share.

You can find it at:

http://ruby.brian-schroeder.de/rpa-completion/

What it can
-----------

- Completion of commands, options and ports


What it is missing
------------------
- Completion of not downloaded ports.
I didn't find a rpa switch to list the known ports.
If someone has an idea, I could add it easily.

regards,

Brian
 
M

Mauricio Fernández

--opJtzjQTFsWo+cga
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

I hacked together a bash completion file for rpa, and wanted to share.

Thanks a lot... I'm definitely adding it to /etc/bash_completion.d: I
use rpa quite often :)

BTW, would it be OK to include it in the next release of rpa-base or
somewhere under http://rpa-base.rubyforge.org ?
You can find it at:

http://ruby.brian-schroeder.de/rpa-completion/

What it can
-----------

- Completion of commands, options and ports


What it is missing

I tried it with GNU bash, version 3.00.0(1)-release (i386-pc-linux-gnu)
and it didn't like the 'have' magic, so I had to comment it out.

Please find attached a patch to allow completion of unknown ports and
discrimination between installed and available ports.

--
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com


--opJtzjQTFsWo+cga
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch

--- rpa.orig 2004-10-12 14:10:19.000000000 +0200
+++ rpa 2004-10-12 14:12:49.000000000 +0200
@@ -4,7 +4,7 @@
# See http://ruby.brian-schroeder.de/ for the latest version.
# License: GNU LGPL v2 or later

-have rpa &&
+#have rpa &&
_rpa() {
local cur prev conns

@@ -12,7 +12,8 @@
cur=${COMP_WORDS[COMP_CWORD]}

RPA_SIMPLE_COMMANDS=(dist list update rollback clean help)
- RPA_PORT_COMMANDS=(install remove build source query search info check)
+ RPA_LOCAL_PORT_COMMANDS=(remove info check)
+ RPA_REMOTE_PORT_COMMANDS=(install build source query search)
RPA_OPTIONS=(-h --help --no-proxy --proxy -q --quiet -x --extended --verbose --debug -v --version \
-f --force -p --parallelize --no-tests -r --requires \
-c --classification -e -eval -D --eval-display)
@@ -22,21 +23,29 @@

for c in ${RPA_SIMPLE_COMMANDS[*]}; do
if [ ${prev} == $c ]; then
- COMPREPLY=( $(compgen -W "$(RPA_OPTIONS)" ${cur}) );
+ COMPREPLY=( $(compgen -W "${RPA_OPTIONS[*]}" ${cur}) );
return 0
fi
done

- for c in ${RPA_PORT_COMMANDS[*]}; do
+ for c in ${RPA_LOCAL_PORT_COMMANDS[*]}; do
if [ ${prev} == $c ]; then
COMPREPLY=( $(compgen -W "$(rpa list | ruby -n -e 'puts $1 if /([-\w]+)\s+[0-9]+/')" ${cur} ) )
return 0
fi
done

+ for c in ${RPA_REMOTE_PORT_COMMANDS[*]}; do
+ if [ ${prev} == $c ]; then
+ COMPREPLY=( $(compgen -W "$(rpa query | ruby -n -e 'puts $1 if /([-\w]+)\s+[0-9]+/')" ${cur} ) )
+ return 0
+ fi
+ done
+
COMPREPLY=( $(compgen -W "${RPA_SIMPLE_COMMANDS[*]} ${RPA_PORT_COMMANDS[*]} ${RPA_OPTIONS[*]}" ${cur} ) )
fi

return 0
}
-[ "$have" ] && complete -F _rpa rpa
+#[ "$have" ] &&
+complete -F _rpa rpa

--opJtzjQTFsWo+cga--
 
B

Brian Schröder

Mauricio said:
Thanks a lot... I'm definitely adding it to /etc/bash_completion.d: I
use rpa quite often :)

BTW, would it be OK to include it in the next release of rpa-base or
somewhere under http://rpa-base.rubyforge.org ?

Sure. Take it and use it. I included your patch.
Maybe you could update your description of the query option. I did not
think that it could be used to display a list of all packages. (I only
saw that it suggested using a port afterwards and thought it was to
query information about a port.) But maybe I was only too fast asleep.

regards,

Brian
 
M

Mauricio Fernández

Sure. Take it and use it. I included your patch.

Great :)
Maybe you could update your description of the query option. I did not
think that it could be used to display a list of all packages. (I only
saw that it suggested using a port afterwards and thought it was to
query information about a port.) But maybe I was only too fast asleep.

You are, of course, right. The command line interface can be made much
better and some steps towards that have already been taken in the 0.3
devel branch.
 
N

nobu.nokada

Hi,

At Tue, 12 Oct 2004 21:20:31 +0900,
Mauricio Fern.ANandez wrote in [ruby-talk:116288]:
Please find attached a patch to allow completion of unknown ports and
discrimination between installed and available ports.

You forgot to change RPA_PORT_COMANDS for compgen.

And improvement for multiple package completion.


# Debian GNU/Linux rpa completion
# Made for "rpa (rpa-base 0.2.2-6) RPA 0.0"
# Copyright 2004 Brian Schr.ANvder <[email protected]>
# See http://ruby.brian-schroeder.de/ for the latest version.
# License: GNU LGPL v2 or later

_rpa() {
local cur prev cmd idx

COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}

RPA_SIMPLE_COMMANDS=(dist list update rollback clean help)
RPA_LOCAL_PORT_COMMANDS=(remove info check)
RPA_REMOTE_PORT_COMMANDS=(install build source query search)
RPA_PORT_COMMANDS=(${RPA_LOCAL_PORT_COMMANDS[*]} ${RPA_REMOTE_PORT_COMMANDS[*]})
RPA_OPTIONS=(-h --help --no-proxy --proxy -q --quiet -x --extended \
--verbose --debug -v --version \
-f --force -p --parallelize --no-tests -r --requires \
-c --classification -e -eval -D --eval-display)

idx=1
while [ $idx -lt $COMP_CWORD ]; do
case "${COMP_WORDS[idx]}" in
-*) ;;
*) prev="${COMP_WORDS[idx]}"; break;;
esac
idx=$[idx+1]
done
if [ ${prev+set} ]; then
case " ${RPA_SIMPLE_COMMANDS[*]} " in
*" $prev "*)
COMPREPLY=( $(compgen -W "${RPA_OPTIONS[*]}" ${cur}) );
return 0;;
esac
case " ${RPA_LOCAL_PORT_COMMANDS[*]} " in
*" $prev "*)
cmd=list;;
esac
case " ${RPA_REMOTE_PORT_COMMANDS[*]} " in
*" $prev "*)
cmd=query;;
esac
if [ "$cmd" ]; then
COMPREPLY=( $(compgen -W "$(rpa $cmd | ruby -n -e 'puts $1 if /([-\w]+)\s+[0-9]+/')" ${cur} ) )
else
COMPREPLY=( $(compgen -W "${RPA_SIMPLE_COMMANDS[*]} ${RPA_PORT_COMMANDS[*]} ${RPA_OPTIONS[*]}" ${cur} ) )
fi
fi

return 0
}
complete -F _rpa rpa

# 10/11/2004: First release
# 10/12/2004: Patch by Mauricio Fern$BaO(Bdez
 
B

Brian Schröder

Thanks for the patch. As soon as I have tested it I'll put it up. I guess thats a complete rewrite, there is not much left of what I put in ;)

I have to admit that I hate shell syntax.

regards,

Brian

On Tue, 19 Oct 2004 11:54:55 +0900
Hi,

At Tue, 12 Oct 2004 21:20:31 +0900,
Mauricio Fern.ANandez wrote in [ruby-talk:116288]:
Please find attached a patch to allow completion of unknown ports and
discrimination between installed and available ports.

You forgot to change RPA_PORT_COMANDS for compgen.

And improvement for multiple package completion.


# Debian GNU/Linux rpa completion
# Made for "rpa (rpa-base 0.2.2-6) RPA 0.0"
# Copyright 2004 Brian Schr.ANvder <[email protected]>
# See http://ruby.brian-schroeder.de/ for the latest version.
# License: GNU LGPL v2 or later

_rpa() {
local cur prev cmd idx

COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}

RPA_SIMPLE_COMMANDS=(dist list update rollback clean help)
RPA_LOCAL_PORT_COMMANDS=(remove info check)
RPA_REMOTE_PORT_COMMANDS=(install build source query search)
RPA_PORT_COMMANDS=(${RPA_LOCAL_PORT_COMMANDS[*]} ${RPA_REMOTE_PORT_COMMANDS[*]})
RPA_OPTIONS=(-h --help --no-proxy --proxy -q --quiet -x --extended \
--verbose --debug -v --version \
-f --force -p --parallelize --no-tests -r --requires \
-c --classification -e -eval -D --eval-display)

idx=1
while [ $idx -lt $COMP_CWORD ]; do
case "${COMP_WORDS[idx]}" in
-*) ;;
*) prev="${COMP_WORDS[idx]}"; break;;
esac
idx=$[idx+1]
done
if [ ${prev+set} ]; then
case " ${RPA_SIMPLE_COMMANDS[*]} " in
*" $prev "*)
COMPREPLY=( $(compgen -W "${RPA_OPTIONS[*]}" ${cur}) );
return 0;;
esac
case " ${RPA_LOCAL_PORT_COMMANDS[*]} " in
*" $prev "*)
cmd=list;;
esac
case " ${RPA_REMOTE_PORT_COMMANDS[*]} " in
*" $prev "*)
cmd=query;;
esac
if [ "$cmd" ]; then
COMPREPLY=( $(compgen -W "$(rpa $cmd | ruby -n -e 'puts $1 if /([-\w]+)\s+[0-9]+/')" ${cur} ) )
else
COMPREPLY=( $(compgen -W "${RPA_SIMPLE_COMMANDS[*]} ${RPA_PORT_COMMANDS[*]} ${RPA_OPTIONS[*]}" ${cur} ) )
fi
fi

return 0
}
complete -F _rpa rpa

# 10/11/2004: First release
# 10/12/2004: Patch by Mauricio Fern$BaO(Bdez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top