[GRASS5] New feature: GRASS-specific completion for bash

Hi All!

I have written a series of shell scripts that setup GRASS-specific completions in bash. Example how it works: you type in any of GRASS commands, e.g. d.rast and press <TAB>. Then you get a list of options for that command. You type in the first letter of an option, then press <TAB> and it completes to a full option. When a command needs a list of raster names, <TAB> will complete on raster names, and so on. I have been using this feature for a while with some of GRASS commands and I have found it rather convenient. Now I have a version that support all GRASS commands. Who can guide me on how to add it to GRASS distribution?

--
Alexandre Sorokine
Department of Geography
University at Buffalo
mailto:sorokine@buffalo.edu

First make it available for us developers somehow so we can take a look.
Can you place it on some server and mail an URL?
(Otherwise individuals of this list might help you out with some
server space.)

Can you make it a package that can be easily installed with grass5.0.0pre4?

If it is nice and after some testing
we can add it to the CVS repository later.

On Tue, May 21, 2002 at 04:01:55PM -0400, Alexandre Sorokine wrote:

Hi All!

I have written a series of shell scripts that setup GRASS-specific
completions in bash. Example how it works: you type in any of GRASS
commands, e.g. d.rast and press <TAB>. Then you get a list of options
for that command. You type in the first letter of an option, then
press <TAB> and it completes to a full option. When a command needs a
list of raster names, <TAB> will complete on raster names, and so on. I
have been using this feature for a while with some of GRASS commands and
I have found it rather convenient. Now I have a version that support
all GRASS commands. Who can guide me on how to add it to GRASS
distribution?

Bernard,

Bernhard Reiter wrote:

First make it available for us developers somehow so we can take a look.
Can you place it on some server and mail an URL?

Here it is: http://www.acsu.buffalo.edu/~sorokine/complete/

Can you make it a package that can be easily installed with grass5.0.0pre4?

Surely I can. Where sould my scripts go on the GRASS directory tree?

If it is nice and after some testing we can add it to the CVS repository later.

On Tue, May 21, 2002 at 04:01:55PM -0400, Alexandre Sorokine wrote:

Hi All!

I have written a series of shell scripts that setup GRASS-specific completions in bash. Example how it works: you type in any of GRASS commands, e.g. d.rast and press <TAB>. Then you get a list of options for that command. You type in the first letter of an option, then press <TAB> and it completes to a full option. When a command needs a list of raster names, <TAB> will complete on raster names, and so on. I have been using this feature for a while with some of GRASS commands and I have found it rather convenient. Now I have a version that support all GRASS commands. Who can guide me on how to add it to GRASS distribution

?

--
Alexandre Sorokine
Department of Geography
University at Buffalo
mailto:sorokine@buffalo.edu

On Friday 24 May 2002 05:51 am, Alexandre Sorokine wrote:

Here it is: http://www.acsu.buffalo.edu/~sorokine/complete/

I have just tested. I like that, it is the feature, I was waiting for.
Few notes:
1) Order of options is obviously alphabetical, may be, that the original
order, coded in module is better? It is based on importance of options.
2) Maybe somehow distinguish optional and required options (map x [type=])
in list.
3) My wish is to have completion for map names - is it possible?

Radim

Radim,

Radim Blazek wrote:

On Friday 24 May 2002 05:51 am, Alexandre Sorokine wrote:

Here it is: http://www.acsu.buffalo.edu/~sorokine/complete/

I have just tested. I like that, it is the feature, I was waiting for.
Few notes:
1) Order of options is obviously alphabetical, may be, that the original order, coded in module is better? It is based on importance of options.

Obviously this is a more ligical way to do it. Unfortunately current version of bash does not give you enough control over how the list of completions is printed out for the user. It looks like bash sorts them using something like LC_COLLATE.

2) Maybe somehow distinguish optional and required options (map x [type=])
in list.

Again this is a bash limitation. My scripts are even aware what parameters are optional and what paprameters are required but I cannot make any use of it now.

What I can do is to print out a one-line help just before the list of completions.

3) My wish is to have completion for map names - is it possible?

Yes, current verion completes on map names, mapsets, monitors and colors. In order to get a list of completion for map names your cursor should be placed on the position just after the equal sign.

--
Alexandre Sorokine
Department of Geography
University at Buffalo
mailto:sorokine@buffalo.edu

On Friday 24 May 2002 06:27 pm, Alexandre Sorokine wrote:

> 3) My wish is to have completion for map names - is it possible?

Yes, current verion completes on map names, mapsets, monitors and
colors. In order to get a list of completion for map names your cursor
should be placed on the position just after the equal sign.

Colors, monitors work, map names, mapsets (dynamic lists) do not.
I think that problem will be in
g_list() # argument is a GRASS data type
{
    local IFS=$''
    echo `g.list $1 | perl -pe 's/^-+$//o; s/^[^:]+:$//o; s/\s+/\n/go'`
}

echo `echo "ab cd" | perl -pe 's/^-+$//o; s/^[^:]+:$//o; s/\s+/\n/go'`
works (for ab, cd maps). Also g.list works there:

echo `g.list $1 | perl -pe 's/^-+$//o; s/^[^:]+:$//o; s/\s+/\n/go'` > err.log

prints to err.log:
GRASS:~/GRASS/bashCompletion/complete > cat err.log

coastline_chch
coastline_dun
coastline_waitaki
pok

i.e. 2 empty rows + my maps.

It seems that it doesn't like empty rows because
g.list vect | sed 's/^-*$//' | sed 's/.*:$//' | tr '\012' ' '
works.

Radim

On Thu, May 23, 2002 at 11:51:05PM -0400, Alexandre Sorokine wrote:

Where sould my scripts go on the GRASS directory tree?

A good question.
What do you propose?

Markus: Any idea?

Bernhard Reiter wrote:

On Thu, May 23, 2002 at 11:51:05PM -0400, Alexandre Sorokine wrote:

Where sould my scripts go on the GRASS directory tree?

A good question.
What do you propose?

Probably they should go into the same place as other initialization scripts under a separate directory. That woould be src/general/init/complete under GRASS source tree and it should install into $GISBASE/etc/complete

Markus: Any idea?

--
Alexandre Sorokine
Department of Geography
University at Buffalo
mailto:sorokine@buffalo.edu