Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-10-27 00:30:25

stardustOne
Member
Registered: 2018-03-09
Posts: 7

How to dynamically change xfce4-terminal title to the current host ?

Hi,

I use xfce-terminal 0.8.9.1

Is there a way to achieve this ?

Thanks

Offline

#2 2022-10-27 01:01:38

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: How to dynamically change xfce4-terminal title to the current host ?

What do you mean by "dynamically change"?

If you are referring to the setting within terminal preferences, see https://docs.xfce.org/apps/xfce4-terminal/4.16/usage.

If you mean something like changing the terminal title to match the host of say a remote ssh connection, then each remote account that you connect to will need to have a similar PROMPT_COMMAND. For example:

PROMPT_COMMAND='printf "\033]0;host: %s\007" "${HOSTNAME%%.*}"'

Within xfce4-terminal settings, make sure you have dynamically set title enabled.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2022-10-27 02:24:49

stardustOne
Member
Registered: 2018-03-09
Posts: 7

Re: How to dynamically change xfce4-terminal title to the current host ?

Thanks, the later is what I meant.

But can I keep my old PS1 too ?

Because I already have a hudge script to feed PROMPT_COMMAND:

[[ -t 0 ]] && stty -ctlecho # eviter ^C affiché dans le term

PURPLE=$(tput setaf 5)
RED=$(tput setaf 1)
WHITE=$(tput setaf 7)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
CYAN=$(tput setaf 4)
LIGHT_CYAN=$(tput setaf 6)
STOP=$(tput sgr0)

for int in eth{0..2} wlan0 ppp{0..2}; do
    IP=$(/sbin/ifconfig 2>/dev/null $int | grep -oP 'inet\s+\K\d+\.\d+\.\d+\.\d+') && break
done


PROMPT_COMMAND=$(

»   cat<<-'EOF'

»   _temp_var=$val_ret _pipe_status="${PIPESTATUS[@]}"

»   if((val_ret==0)); then
»   »   _temp_var=$(( $(tr -s " " "+" <<< "$_pipe_status") ))
»   else
»   »   _temp_var=$val_ret
»   fi

»   if((_temp_var!=0)); then
»   »   if((EUID==0)); then
»   »   »   PS1="\[$RED\]\u\[$YELLOW\]@\[$WHITE\]\h\[$CYAN\]:\[$GREEN\]\w\[$WHITE\]\[$GREEN\]|\[$RED\]ERROR:$_temp_var\[$GREEN\]|\[$WHITE\] # \[$STOP\]"
»   »   else
»   »   »   PS1="\[$PURPLE\]\u\[$WHITE\]@\[$GREEN\]\h\[$GREEN\][\[$STOP\]${IP:-<UNDEF>}\[$GREEN\]]\[$WHITE\]:\[$GREEN\]\w|\[$RED\]ERROR:$_temp_var\[$GREEN\]|\[$WHITE\]$ $ \[$STOP\]"
»   »   fi

»   else
»   »   if((EUID==0)); then
»   »   »   PS1="\[$RED\]\u\[$YELLOW\]@\[$WHITE\]\h\[$CYAN\]:\[$GREEN\]\w\[$WHITE\] # \[$STOP\]"
»   »   else
»   »   »   PS1="\[$PURPLE\]\u\[$WHITE\]@\[$GREEN\]\h\[$WHITE\]:\[$GREEN\]\w\[$WHITE\] $ \[$STOP\]"
»   »   fi
»   fi

»   EOF

Last edited by stardustOne (2022-10-27 02:29:13)

Offline

#4 2022-10-27 09:56:06

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: How to dynamically change xfce4-terminal title to the current host ?

Try adding after that block the following:

PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;host: %s\007" "${HOSTNAME%%.*}"'

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2022-10-27 22:03:34

stardustOne
Member
Registered: 2018-03-09
Posts: 7

Re: How to dynamically change xfce4-terminal title to the current host ?

Thanks !

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.012 seconds, 7 queries executed - Memory usage: 534.03 KiB (Peak: 534.88 KiB) ]