[GRASS-dev] [GRASS GIS] #1369: setPrompt: command not found in GRASS7-svn

#1369: setPrompt: command not found in GRASS7-svn
-------------------------+--------------------------------------------------
Reporter: moovida | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone:
Component: Startup | Version: svn-trunk
Keywords: | Platform: Linux
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
The grass7 command shell doesn't appear to permit to have an own
setPrompt.

I use a customized one to have some different information/coloring of the
prompt in the case of git and hg repos:

function setPrompt(){
     thedate=`date "+%F %T"`
     if [ -d ./.git ]; then
         GITBRANCH="$NC($GREEN$(awk -F '/' '{ print $NF }' .git/HEAD)$NC"

         if [ $(git diff --exit-code > /dev/null 2>&1; echo $?) -eq 1 ] ||
[ $(git diff-index --cached --quiet --ignore-submodules HEAD --; echo $?)
-eq 1 ]; then
           GITBRANCH="$GITBRANCH [$RED*$NC"
         else
           GITBRANCH="$GITBRANCH [$MAGENTA-$NC"
         fi

         if [ "x$(git status | grep Untracked)" != "x" ]; then
           GITBRANCH="$GITBRANCH$RED+$NC])"
         else
           GITBRANCH="$GITBRANCH$MAGENTA-$NC])"
         fi
         echo -e "\n${GREEN}GIT:${NC} ${GITBRANCH}"
         echo -e
"${GREEN}======================================================
$thedate${NC}\n\n\w >>> "
     elif [ -d ./.hg ]; then
         HGBRANCH="$NC($CYAN$(awk -F '/' '{ print $NF }' .hg/branch)$NC"

         if [ "x`hg status | grep ?`" != "x" ]; then
           HGBRANCH="$HGBRANCH [$RED+$NC])"
         else
           HGBRANCH="$HGBRANCH [$MAGENTA-$NC])"
         fi

         echo -e "\n${CYAN}HG:${NC} ${HGBRANCH}"
         echo -e
"${CYAN}======================================================
$thedate${NC}\n\n\w >>> "
     else
         echo -e
"${RED}======================================================
$thedate${NC}\n\n\w >>> "
     fi
}

which leads me to the error in the subject.

While for example in grass64 I have:
GRASS 6.4.0+42329 (gbovest):~ > echo $PROMPT_COMMAND
'/usr/lib/grass64/etc/prompt.sh'

in grass7 it seems to have changed to:
echo $PROMPT_COMMAND
PS1="$(setPrompt)"

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1369&gt;
GRASS GIS <http://grass.osgeo.org>

#1369: setPrompt: command not found in GRASS7-svn
-------------------------+--------------------------------------------------
Reporter: moovida | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Startup | Version: svn-trunk
Keywords: | Platform: Linux
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
Changes (by martinl):

  * milestone: => 7.0.0

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1369#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1369: setPrompt: command not found in GRASS7-svn
-------------------------+--------------------------------------------------
Reporter: moovida | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Startup | Version: svn-trunk
Keywords: | Platform: Linux
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
Description changed by neteler:

Old description:

The grass7 command shell doesn't appear to permit to have an own
setPrompt.

I use a customized one to have some different information/coloring of the
prompt in the case of git and hg repos:

function setPrompt(){
    thedate=`date "+%F %T"`
    if [ -d ./.git ]; then
        GITBRANCH="$NC($GREEN$(awk -F '/' '{ print $NF }' .git/HEAD)$NC"

        if [ $(git diff --exit-code > /dev/null 2>&1; echo $?) -eq 1 ] ||
[ $(git diff-index --cached --quiet --ignore-submodules HEAD --; echo $?)
-eq 1 ]; then
          GITBRANCH="$GITBRANCH [$RED*$NC"
        else
          GITBRANCH="$GITBRANCH [$MAGENTA-$NC"
        fi

        if [ "x$(git status | grep Untracked)" != "x" ]; then
          GITBRANCH="$GITBRANCH$RED+$NC])"
        else
          GITBRANCH="$GITBRANCH$MAGENTA-$NC])"
        fi
        echo -e "\n${GREEN}GIT:${NC} ${GITBRANCH}"
        echo -e
"${GREEN}======================================================
$thedate${NC}\n\n\w >>> "
    elif [ -d ./.hg ]; then
        HGBRANCH="$NC($CYAN$(awk -F '/' '{ print $NF }' .hg/branch)$NC"

        if [ "x`hg status | grep ?`" != "x" ]; then
          HGBRANCH="$HGBRANCH [$RED+$NC])"
        else
          HGBRANCH="$HGBRANCH [$MAGENTA-$NC])"
        fi

        echo -e "\n${CYAN}HG:${NC} ${HGBRANCH}"
        echo -e
"${CYAN}======================================================
$thedate${NC}\n\n\w >>> "
    else
        echo -e
"${RED}======================================================
$thedate${NC}\n\n\w >>> "
    fi
}

which leads me to the error in the subject.

While for example in grass64 I have:
GRASS 6.4.0+42329 (gbovest):~ > echo $PROMPT_COMMAND
'/usr/lib/grass64/etc/prompt.sh'

in grass7 it seems to have changed to:
echo $PROMPT_COMMAND
PS1="$(setPrompt)"

New description:

The grass7 command shell doesn't appear to permit to have an own
setPrompt.

I use a customized one to have some different information/coloring of the
prompt in the case of git and hg repos:

{{{
function setPrompt(){
     thedate=`date "+%F %T"`
     if [ -d ./.git ]; then
         GITBRANCH="$NC($GREEN$(awk -F '/' '{ print $NF }' .git/HEAD)$NC"

         if [ $(git diff --exit-code > /dev/null 2>&1; echo $?) -eq 1 ] ||
[ $(git diff-index --cached --quiet --ignore-submodules HEAD --; echo $?)
-eq 1 ]; then
           GITBRANCH="$GITBRANCH [$RED*$NC"
         else
           GITBRANCH="$GITBRANCH [$MAGENTA-$NC"
         fi

         if [ "x$(git status | grep Untracked)" != "x" ]; then
           GITBRANCH="$GITBRANCH$RED+$NC])"
         else
           GITBRANCH="$GITBRANCH$MAGENTA-$NC])"
         fi
         echo -e "\n${GREEN}GIT:${NC} ${GITBRANCH}"
         echo -e
"${GREEN}======================================================
$thedate${NC}\n\n\w >>> "
     elif [ -d ./.hg ]; then
         HGBRANCH="$NC($CYAN$(awk -F '/' '{ print $NF }' .hg/branch)$NC"

         if [ "x`hg status | grep ?`" != "x" ]; then
           HGBRANCH="$HGBRANCH [$RED+$NC])"
         else
           HGBRANCH="$HGBRANCH [$MAGENTA-$NC])"
         fi

         echo -e "\n${CYAN}HG:${NC} ${HGBRANCH}"
         echo -e
"${CYAN}======================================================
$thedate${NC}\n\n\w >>> "
     else
         echo -e
"${RED}======================================================
$thedate${NC}\n\n\w >>> "
     fi
}
}}}

which leads me to the error in the subject.

While for example in grass64 I have:

{{{
GRASS 6.4.0+42329 (gbovest):~ > echo $PROMPT_COMMAND
'/usr/lib/grass64/etc/prompt.sh'
}}}

in grass7 it seems to have changed to:

{{{
echo $PROMPT_COMMAND
PS1="$(setPrompt)"
}}}

--

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1369#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#1369: setPrompt: command not found in GRASS7-svn
----------------------+-----------------------------------------------------
  Reporter: moovida | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: Startup | Version: svn-trunk
Resolution: wontfix | Keywords:
  Platform: Linux | Cpu: Unspecified
----------------------+-----------------------------------------------------
Changes (by wenzeslaus):

  * status: new => closed
  * resolution: => wontfix

Comment:

Currently:
{{{
> echo $PROMPT_COMMAND
grass_prompt
}}}

I think GRASS is not honoring the standard `.bashrc` in home by purpose if
this is what are you trying to achieve. There are some discussion on
mailing list about that.

[GRASS-SVN] r61051 - grass/trunk/lib/init
  * http://lists.osgeo.org/pipermail/grass-dev/2014-July/069943.html
  * http://osgeo-org.1560.x6.nabble.com/Re-GRASS-SVN-r61051-grass-trunk-
lib-init-td5149672.html

[GRASS-dev] Bash aliases in GRASS
  * http://lists.osgeo.org/pipermail/grass-dev/2013-February/061837.html
  * http://osgeo-org.1560.x6.nabble.com/Bash-aliases-in-GRASS-
td5032707.html

[GRASS-user] loss of bash aliases
  * http://lists.osgeo.org/pipermail/grass-user/2008-March/043806.html
  * http://osgeo-org.1560.x6.nabble.com/loss-of-bash-aliases-td3927364.html

I think you need to use `~/.grass7/bashrc`. Citing from one of the
discussions:

> > So we have $LOCATION/.bashrc, ~/.grass7/bashrc, and ~/.grass.bashrc.
Do they
> > all have different purposes and are they documented clearly somewhere?
> > (Huidae)
> `.grass.bashrc` is related to GRASS 6. GRASS 7 stores environmental
> variables in `~/.grass7/bashrc`. The init script in GRASS 7 also reads
> `.grass.bashrc` for backward compatibility.
> (Martin)

I'm afraid that this is wontfix/invalid (feature, not a bug). Perhaps
should be documented better. Feel free to suggest location and wording.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1369#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#1369: setPrompt: command not found in GRASS7-svn
----------------------+-----------------------------------------------------
  Reporter: moovida | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: Startup | Version: svn-trunk
Resolution: wontfix | Keywords: shell, prompt
  Platform: Linux | Cpu: Unspecified
----------------------+-----------------------------------------------------
Changes (by hamish):

  * keywords: => shell, prompt

Comment:

for me this was working fine for me last time I had a MASK map set,

{{{
GRASS7> echo $PROMPT_COMMAND
'/home/hamish/src/grass/svn/trunk/dist.x86_64-unknown-linux-
gnu/etc/prompt.py'
}}}

As such, I would suggest that this bug is already fixed, not wontfix.

the place the prompt.py is set is in lib/init/grass.py line ~1085.
Prompt.py is also in lib/init/ in the source tree.

fwiw I doubt that has to be or should be a python script, and I think it
only slows things down to have it as such. By definition the bash prompt
is going to have a Bourne shell already present and already cached in
memory, and launching a python process is much more expensive than a built
in function().

ISTR some trouble with this last time I tried G7 from the cmd.exe line on
Windows, it had trouble finding the right python interpreter? Would need
to recheck if that is still the case. Rather that worry about fixing that
I'd again suggest to just put it back to a shell script and avoid the
headache.

Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1369#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#1369: setPrompt: command not found in GRASS7-svn
----------------------+-----------------------------------------------------
  Reporter: moovida | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: Startup | Version: svn-trunk
Resolution: wontfix | Keywords: shell, prompt
  Platform: Linux | Cpu: Unspecified
----------------------+-----------------------------------------------------

Comment(by hcho):

You have to define grass_prompt() in ~/.grass7/bashrc:
{{{
grass_prompt(){
   # your code here
}
}}}

prompt.py has already been replaced by grass_prompt() in trunk because of
#2284.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1369#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>