[GRASS-dev] [GRASS GIS] #2284: Keep pressing Ctrl+C in command line

Glynn Clements glynn at gclements.plus.com
Mon May 12 15:37:27 PDT 2014


Huidae Cho wrote:

> Would I miss any functionalities by using prompt.sh?

No.

> I mean other than portability between OSs,

prompt.py doesn't provide that. The only way in which the script is
executed is by setting the bash variable PROMPT_COMMAND. If set, bash
treats its value as a command to execute prior to displaying the
primary prompt ($PS1).

If you're using bash, you can use either prompt.sh or prompt.py (or
something of your own devising, or nothing). If you aren't using bash,
neither of those scripts are of any use to you.

> does prompt.py provide other benefits? If there's
> nothing to lose in Unix by falling back to prompt.sh, I'd like to bring it
> into 7 and let the user choose. Maybe if the user is in Unix, there is no
> reason at all to use prompt.py?

I'm not sure that we need a choice. Actually, I'm not sure that we
even need a separate script (in any language). $PROMPT_COMMAND can be
any bash command; it doesn't have to be an external program. We could
just insert the appropriate code as a bash function into the custom
<mapset>/.bashrc file generated by the startup script.

IOW, in lib/init/grass.py, replace
    
    f.write("PROMPT_COMMAND=\"'%s'\"\n" % os.path.join(gisbase, 'etc',
                                                       'prompt.py'))

with

    f.write("""
grass_prompt () {
LOCATION="`g.gisenv GISDBASE`/`g.gisenv LOCATION_NAME`/`g.gisenv MAPSET`"
if test -d "$LOCATION/grid3/G3D_MASK" && test -f "$LOCATION/cell/MASK" ; then
    echo [Raster and Volume MASKs present]
elif test -f "$LOCATION/cell/MASK" ; then
    echo [Raster MASK present]
elif test -d "$LOCATION/grid3/G3D_MASK" ; then
    echo [Volume MASK present]
fi
}
PROMPT_COMMAND=grass_prompt
""")        

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list