3

I have two terminals installed, gnome-terminal and xfce4-terminal.

I would like to have only the xfce terminal showing a simple > as prompt when I start it. The gnome-terminal prompt should remain unchanged (so no bashrc modification, I think).

I don't mind starting xfce-terminal from a script or another terminal with some parameters.

I tried:

xfce4-terminal -x export PS1='> '

but that throws an error and is apparently not do-able.

Any solution is welcome, even if it's a bit hackish

4 Answers 4

1

Do change your .bashrc, and test the name of the parent process.

parent_process=$(ps -o comm= -p $PPID)
parent_process=${parent_process##*/}
case "$parent_process" in
  xfce4-terminal) PS1='> ';;
esac

Another method would be to set an environment variable: run PROMPT_THEME=plain xfce4-terminal and test the value of PROMPT_THEME in your .bashrc. You may want to unset or at least unexport the variable there, as otherwise it will also be set in terminals started from within that first one.

case $PROMPT_THEME in
  plain) PS1='> ';;
esac
export -n PROMPT_THEME

With xfce4-terminal, this won't work except for the first instance, because subsequent instances merely notify the running instance to open a new window, so new instances inherit the environment from the running one. (Yeech!) You can instead set the environment variable through the command that you start in the terminal, with the env utility.

xfce4-terminal -x env PROMPT_THEME=plain bash
1
  • +1 for the PROMPT_THEME suggestion.
    – chepner
    Commented Nov 3, 2014 at 15:32
0

Check which terminal is being opened:

 case "$TERM" in
    gnome-terminal ) PS1="[\h] \W > \[\033]0;[\u@\h] \w\007\]"
        ;;
    xfce4-terminal ) PS1="> "
        ;;
    esac
3
  • Thanks for the answer, but I tried your code at the bottom of my .bashrc and rebooted. It had no effect (although I'm not sure why seems like it should work).
    – Juicy
    Commented Nov 2, 2014 at 1:03
  • 1
    gnome-terminal and xfce-terminal are not valid value for $TERM i don't believe. Look at askubuntu.com/questions/233280/… suggests checking $COLORTERM . i have not tested
    – ptierno
    Commented Nov 2, 2014 at 1:21
  • @Juicy I don't have accesss to either terminal; but according to Petey T's link you should be able to change "$TERM" to "$COLORTERM"... To be sure, echo "$TERM" in both terminals.
    – jasonwryan
    Commented Nov 2, 2014 at 1:42
0

If your ~/.bashrc doesn't set PROMPT_COMMAND, you can start xfce4-terminal as:

PROMPT_COMMAND='PS1="> "; unset PROMPT_COMMAND' xfce4-terminal
0

One way to do this would be to start with the current BASH PID (you get it with $$) and then get the PPID, and so on, until you find what terminal is the ancestor of the bash shell. Based on that information then you set the PS.

Usually the parent of the shell will be the terminal

Proof of concept in my system (Debian 7).

$ PARENT_PID=$(ps --pid=$$ -o ppid --no-headers)
$ ps --pid $PARENT_PID -o command --no-headers
gnome-terminal -x /bin/sh -c cd '/home/XXXX/Desktop' && exec $SHELL

So, in my system is enough to look to the shell's parent to find that it is being run from a gnome terminal.

Condensed in one line:

$ ps --pid $(ps --pid=$$ -o ppid --no-headers) -o command --no-headers
gnome-terminal -x /bin/sh -c cd '/home/XXXX/Desktop' && exec $SHELL

I tried and added this line to my .bashrc

MY_TERMINAL=$(ps --pid $(ps --pid=$$ -o ppid --no-headers) -o command --no-headers | cut -f 1 -d " ")

And I verified that MY_TERMINAL contains gnome-terminal.

So, that should do it.

2
  • Why are you looking at the grandparent of the shell? The terminal emulator is the parent of the shell, unless there's some weirdness in your configuration that causes an intermediate process. In a normal setup, the grandparent will be the window manager or whatever started the terminal emulator. Commented Nov 2, 2014 at 13:40
  • You are right. Commands were OK but naming was wrong. It should say parent not grandparent. Corrected. Thanks. Commented Nov 6, 2014 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .