[GRASS-dev] Custom GRASS command line prompt
Nikos Alexandris
nik at nikosalexandris.net
Mon Dec 15 03:15:13 PST 2014
On 15.12.2014 12:33, Michel Wortmann wrote:
> Hi Nikos, Hamish and list,
> you guys played around with your commandline prompts last year (see
> below), I was just implementing the same thing into my
> ~/.grass.bashrc
> (GRASS 7.0.0b3) but found that the location and mapset arent actually
> changed when changing them with g.mapset, i.e. .grass.bashrc isnt
> actually executed again.
> Whats the best way getting that to work with or without changing
> source or $GISBASE files?
Hi Michel! How nice that someone else is doing this as well :-). I
don't think I changed much since -- here is my current setup:
--%<---
SHORT_VER=`echo "$GRASS_VERSION" | cut -f1,2 -d. | sed -e 's/\.//'`
GDBASE=`g.gisenv get=GISDBASE | rev | cut -d"/" -f1 | rev`
GLOCATION=`g.gisenv get="LOCATION_NAME"`
GMAPSET=`g.gisenv get="MAPSET"`
export PROMPT_DIRTRIM=2
# export PS1='\e[32;40mG$SHORT_VER\e[0m [\e[34;40m${GLOCATION}\e[0m /
\e[32;40m${GMAPSET}\e[0m] :\e[36;40m\w \e[0m[\#/\!] \n\r\e[32;40m>\e[0m
'
export PS1='\[\e[32m\]G$SHORT_VER\[\e[0m\] [ ${GDBASE} /
\[\e[33m\]${GLOCATION}\[\e[0m\] @\[\e[32;1m\]${GMAPSET}\[\e[0m\] ] :
\[\e[36m\]\w \[\e[0m\][\#/\!]
\[\e[32;1m\]>\[\e[0m\] '
--->%--
and, you are right, the Mapset isn't updated. The Location, me thinks,
should not change, or should only in special cases. We don't usually
switch Location's from inside a grass session. We do switch Mapsets.
But we should be careful because we need to manually instruct the use of
the "new" history log once changed to another Mapset ("history -w;
history -r" etc). Right?
Otherwise, I came with a stupid solution, a function inside
"grass.bashrc" to re-source itself:
--%<---
# Re-Source Me!
g.src()
{
source ~/.grass.bashrc
}
--->%--
I tested it and it works. Change a mapset and then `g.src` or whatever
you might name it. Don't know if it's dangerous though.
Let us know if you come up with something smart. I would love to see a
zsh like behaviour inside grass shell. Would be awesome.
Nikos
More information about the grass-dev
mailing list