[GRASS-dev] Custom GRASS command line prompt

I want to alter the default GRASS command line prompt. For my needs, I find it better to have the current Mapset shown along with the Location.

As a first experiment, I edited the corresponding file in place:

grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp, line 1039:

  • f.write(“PS1='GRASS %s (%s):\w > '\n” % (grass_version, location_name))
  • f.write(“PS1='G %s (%s/%s):\w > '\n” % (grass_version, location_name, mapset))

Now it appears like: “G 7.0.svn (utm_37s/post):~ >”. My understanding is that I probably need to edit the file:

grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp

Do you have customised prompts? Any ideas for a more productive command line?

Thanks, Nikos

Nikos:

I want to alter the default GRASS command line prompt. For my needs,
I find it better to have the current Mapset shown along with the
Location.

As a first experiment, I edited the corresponding file in place:
grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp, line 1039:

- f.write("PS1='GRASS %s (%s):\w > '\n" % (grass_version, location_name))
+ f.write("PS1='G %s (%s/%s):\w > '\n" % (grass_version, location_name, mapset))

Now it appears like: "G 7.0.svn (utm_37s/post):~ >". My understanding is
that I probably need to edit the file:
grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp

Do you have customised prompts? Any ideas for a more productive
command line?

I'd suggest to put the change in ~/.grass.bashrc instead.

fwiw here's what I have there wrt the prompt:

SHORT_VER=`echo "$GRASS_VERSION" | cut -f1,2 -d. | sed -e 's/\.//'`
export PS1='G$SHORT_VER:\W > '
export HISTSIZE=3000

.or.

export PS1='G$SHORT_VER:\w > '
export PROMPT_DIRTRIM=2

as full dir path gets much too long, especially on WinGrass where the
terminal width is a pain to resize.

For simplicity one of my favourites is still just:

export PS1='GRASS$SHORT_VER> '

If you do most of your work with a small set of locations, it might
also be an idea to figure something out with Xresources to color the
terminal background based on which one you're running in.

regards,
Hamish

Nikos:

I want to alter the default GRASS command line prompt.

As a first experiment, I edited the corresponding file in place:

grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp, line 1039:

f.write(“PS1='G %s (%s/%s):\w > '\n” % (grass_version, location_name,

mapset))

Now it appears like: “G 7.0.svn (utm_37s/post):~ >”. My understanding is

that I probably need to edit the file:

grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp

Do you have customised prompts? Any ideas for a more productive

command line?

Hamish wrote:

I’d suggest to put the change in ~/.grass.bashrc instead.

Somehow it got stuck in my mind that I need to do it in the source…

fwiw here’s what I have there wrt the prompt:

SHORT_VER=echo "$GRASS_VERSION" | cut -f1,2 -d. | sed -e 's/\.//'

export PS1='G$SHORT_VER:\W > ’

Yes! Was thinking exactly about Gxx :slight_smile:

export HISTSIZE=3000

here: export HISTSIZE=15000 :smiley:

.or.

export PS1='G$SHORT_VER:\w > ’

export PROMPT_DIRTRIM=2

as full dir path gets much too long, especially on WinGrass where the

terminal width is a pain to resize.

Just a thought: would be nice to customise as to have a top or a bottom “info-line”, or two “info-lines” below 80 chars (what’s the max that should be respected?), like

show a “+” for many Mapsets------------------- vvv

v

,–%<—

|Gxx | Location/Mapset [Mapset2 Mapset3 Mapset4 +] Datum Units

| n=1111111 s=22222222 w=333333 e=444444 ns=4 ew=4 cells=4664r x 4446c

`—>%–

or stuff can go in the terminals title-bar – this, I guess, works easily with a few terminals like xterm.

For simplicity one of my favourites is still just:

export PS1='GRASS$SHORT_VER> ’

If you do most of your work with a small set of locations, it might

also be an idea to figure something out with Xresources to color the

terminal background based on which one you’re running in.

Nice!! I was looking the past week at http://www.funtoo.org/Prompt_Magic.

Thanks a lot!

Nikos

Nikos:

Now it appears like: “G 7.0.svn (utm_37s/post):~ >”. My understanding is

that I probably need to edit the file:

grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp

Hamish:

I’d suggest to put the change in ~/.grass.bashrc instead.

Hamish,

don’t want to waist your time, but I have put soemthing like

SHORT_VER=echo "$GRASS_VERSION" | cut -f1,2 -d. | sed -e 's/\.//'

GLOCATION=echo "${LOCATION_NAME}"

GMAPSET=echo "${MAPSET}"

export PS1='G$SHORT_VER ${GLOCATION}/${GMAPSET}:\w > ’

export PROMPT_DIRTRIM=2

which doesn’t work! :-/

Where should $LOCATION_NAME, $MAPSET be fed from?

Thanks, N

Nikos:

> Now it appears like: "G 7.0.svn (utm_37s/post):~ >". My understanding is
> that I probably need to edit the file:
> grass7_trunk/dist.x86_64-unknown-linux-gnu/grass70.tmp

Hamish:

I'd suggest to put the change in ~/.grass.bashrc instead.

Nikos:

Hamish,

don't want to waist your time, but I have put soemthing like

SHORT_VER=`echo "$GRASS_VERSION" | cut -f1,2 -d. | sed -e 's/\.//'`
GLOCATION=`echo "${LOCATION_NAME}"`
GMAPSET=`echo "${MAPSET}"`
export PS1='G$SHORT_VER ${GLOCATION}/${GMAPSET}:\w > '
export PROMPT_DIRTRIM=2

which doesn't work! :-/

Where should $LOCATION_NAME, $MAPSET be fed from?

I got it...

GLOCATION=`g.gisenv get="LOCATION_NAME"`
GMAPSET=`g.gisenv get="MAPSET"`

Nikos

Nikos:

Just a thought: would be nice to customise as to have a top or a
bottom "info-line", or two "info-lines" below 80 chars (what's the
max that should be respected?),

see MarkusN's "[Raster MASK present]" command prompt magic using

"$PROMPT_COMMAND" (set in $GISBASE/etc/Init.sh).

or stuff can go in the terminals title-bar -- this, I
guess, works easily with a few terminals like xterm.

see $GISBASE/etc/grass-run.sh

re. using terminal colors, a web-search finds a number of pages like this:
http://superuser.com/questions/270214/how-can-i-change-the-colors-of-my-xterm-using-ansi-escape-sequences
# putting that into practice:
CLEAR='\e[2J\e[1;1H'
FG_CYAN='\e[36m'
BG_BLUE='\e[44m'

echo -en "${FG_CYAN}${BG_BLUE}$CLEAR"

# example of adding an RGB border color with a #RRGGBB code:
echo -ne "\033]11;#53186f\007"

for me, xfce4-terminal and rxvt accepted the old EGA colors for fore/background,
but not the full RGB border -- I had to use xterm to see that work.

But I think changing the border with a RGB color per mapset or location would
scale better if you were having a different color for each mapset/location.
Or, for the "MASK present" I'd prefer a red terminal border to the extra line
on the command prompt, so it might be nice to search out what the different
escape codes for gnome-terminal et al. might be.

Hamish

On Sun, Jul 28, 2013 at 4:50 AM, Hamish <hamish_b@yahoo.com> wrote:
...

fwiw here's what I have there wrt the prompt:

SHORT_VER=`echo "$GRASS_VERSION" | cut -f1,2 -d. | sed -e 's/\.//'`
export PS1='G$SHORT_VER:\W > '
export HISTSIZE=3000

Personally I would suggest 30000 lines here (I use 50k). Better save
than sorry :slight_smile:

Markus

Hamish:

fwiw here’s what I have there wrt the prompt:

SHORT_VER=echo "$GRASS_VERSION" | cut -f1,2 -d. | sed -e 's/\.//'

export PS1='G$SHORT_VER:\W > ’

export HISTSIZE=3000

Markus Neteler wrote:

Personally I would suggest 30000 lines here (I use 50k). Better save

than sorry :slight_smile:

In reality, I forgot to mention that in /home/nik/.bashrc I have

declare -x HISTFILESIZE=1000000000

declare -x HISTSIZE=1000000

Ha-ha… :smiley:

Nikos

Hamish wrote:

# example of adding an RGB border color with a #RRGGBB code:
echo -ne "\033]11;#53186f\007"

...

But I think changing the border with a RGB color per mapset
or location would scale better if you were having a different
color for each mapset/location.
Or, for the "MASK present" I'd prefer a red terminal border to the
extra line on the command prompt, so it might be nice to search out
what the different escape codes for gnome-terminal et al. might be.

hmm, doesn't work so well.

xterm:
echo -e "\e]11;#aa186f\007"
CLEAR='\e[2J\e[1;1H'
echo -ne "\e[37m\e[40m$CLEAR"
unset CLEAR

this sets the internalBorder resource (xterm -b) color, but as soon
as something wraps around column 80 it stops being the border color and becomes the background color.

it would be nice to figure a way to get the border color working properly though.

Hamish

Hamish wrote:

# example of adding an RGB border color with a #RRGGBB code:
echo -ne "\033]11;#53186f\007"

...

But I think changing the border with a RGB color per mapset
or location would scale better if you were having a different
color for each mapset/location.
Or, for the "MASK present" I'd prefer a red terminal border to the
extra line on the command prompt, so it might be nice to search out
what the different escape codes for gnome-terminal et al. might be.

hmm, doesn't work so well.

this sets the border color in xterm:

echo -e "\e]11;#aa186f\007"
CLEAR='\e[2J\e[1;1H'
echo -ne "\e[37m\e[40m$CLEAR"
unset CLEAR

..for the internalBorder Xresource (xterm -b), but as soon as something wraps around column 80 it stops being the border color and becomes the background color.

it would be nice to figure a way to get the border color working properly though since it seems like a nice way to do it.

Hamish

Nkos:

> Do you have customised prompts? Any ideas for a more productive
> command line?

Hamish:

I'd suggest to put the change in ~/.grass.bashrc instead.

FWIW,

I use now the following

export PS1='\[\e[32m\]G$SHORT_VER\[\e[0m\] [ \[\e[33m\]${GLOCATION}\[\e[0m\]
@\[\e[32;1m\]${GMAPSET}\[\e[0m\] ] : \[\e[36m\]\w \[\e[0m\]
\[\e[32;1m\]>\[\e[0m\] '

Apart from the colors (with which I was exeprimenting) I think it's much
cleaner now -- info as a "top" line and the ">" right below in a new line. It
looks like:

,--%<---
G70 [ utm_37s @change_detection ] : .../grassdb/onsight

`--->%--

This eats-up one line. But, 1) it gives all the space for longer commands and
2) it works as a useful "separator" (especially if it is colorised) and makes
searching "back in time" easier.

Nikos

On Monday 29 of July 2013 17:29:29 Hamish wrote:

Hamish wrote:
> # example of adding an RGB border color with a #RRGGBB code:
> echo -ne "\033]11;#53186f\007"

...

> But I think changing the border with a RGB color per mapset
> or location would scale better if you were having a different
> color for each mapset/location.
> Or, for the "MASK present" I'd prefer a red terminal border to the
> extra line on the command prompt, so it might be nice to search out
> what the different escape codes for gnome-terminal et al. might be.

hmm, doesn't work so well.

this sets the border color in xterm:

echo -e "\e]11;#aa186f\007"
CLEAR='\e[2J\e[1;1H'
echo -ne "\e[37m\e[40m$CLEAR"
unset CLEAR

..for the internalBorder Xresource (xterm -b), but as soon as something
wraps around column 80 it stops being the border color and becomes the
background color.

it would be nice to figure a way to get the border color working properly
though since it seems like a nice way to do it.

Yep, it makes "everything" magenta-like. A pity this doesn't work as wanted.
Really good idea. We can always ask... at stackexchange?

Nikos

Hamish