Xfce Forum

Sub domains
 

You are not logged in.

#1 2020-04-28 16:55:06

orschiro
Member
Registered: 2017-11-30
Posts: 54

Terminal preferences: show running command in title? [solved]

Hi guys,

Question about this setting:

6v2WKRT.png

Can I tweak this setting to show the currently running command?

Let's say, inside that terminal I am running the command "sleep 1m", then I want the terminal title to be "sleep 1m", instead of the current directory name.

Thanks for any hints!

Last edited by orschiro (2021-02-08 13:08:58)

Offline

#2 2020-04-28 17:52:19

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

Assuming bash, you can add the following to your .bashrc:

trap 'echo -ne "\033]2;$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//g")\007"' DEBUG

This will put the name of the current running (or last run) command in your terminal title.

Online

#3 2020-04-29 05:58:03

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

Thanks. I added your line and launched a new terminal window but it's not doing the trick. See below.

QnRbcor.png

Offline

#4 2020-04-29 10:53:53

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

Have you sourced your .bashrc file after making the change?

. ~/.bashrc

...or logged out and back in again?

Also assuming that you still have "Dynamically Set Title" set to "Replaces initial title"
Screenshot-2020-04-29-06-51-56.png

Online

#5 2020-04-29 10:58:22

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

If I am sourcing using your command, I am running into this error:

[orschiro@x230 ~]$ . ~/.bashrc
. ~/.bashrc/home/orschirobash: 1588157857 - 1588157857 : syntax error: operand expected (error token is "1588157857 - 1588157857 ")

Offline

#6 2020-04-29 11:33:46

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

Which version of xfce4-terminal are you running?
Can you post your ~/.bashrc file?
And confirm your shell:

echo $SHELL

Looks like you need this combination of directives in your ~/.bashrc file to make it also remember the last run command:

export PROMPT_COMMAND='history -a'
trap 'echo -ne "\033]2;$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//g")\007"' DEBUG

The first directive saves any command run into your history file and the second one displays it in the title bar. Without the first directive, it only shows running commands in the titlebar (like "sleep 1m").

I'm testing this on version 0.8.9.2 on arch linux.

Online

#7 2020-04-29 11:37:22

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

- xfce4-terminal 0.8.9.1 (Xfce 4.14)

.bashrc:

[orschiro@x230 ~]$ cat .bashrc 
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

# source fzf key bindings
if [ -f /usr/share/fzf/shell/key-bindings.bash ]; then
        . /usr/share/fzf/shell/key-bindings.bash
fi

# source autojump
# if [ -f /etc/profile.d/autojump.sh ]; then
# 	. /etc/profile.d/autojump.sh
# fi

# source thefuck
# eval $(thefuck --alias)

source /etc/profile.d/undistract-me.sh

# show running command in terminal title
# https://forum.xfce.org/viewtopic.php?pid=57840#p57840
trap 'echo -ne "\033]2;$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//g")\007"' DEBUG
[orschiro@x230 ~]$ echo $SHELL
/bin/bash

Offline

#8 2020-04-29 11:39:47

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

Looks like you need this combination of directives in your ~/.bashrc file to make it also remember the last run command:

This seems to work better BUT, once the command terminates, it doesn't revert to the default directory title which I would prefer.

bznkHeC.png

Offline

#9 2020-04-29 19:15:22

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

orschiro wrote:

This seems to work better BUT, once the command terminates, it doesn't revert to the default directory title which I would prefer.

Try removing the "export PROMPT_COMMAND='history -a'" from your bash shell. That's what makes the command stay, I believe (or thats what happens on my system).

Online

#10 2020-04-30 11:19:47

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

Thanks ToZ. Appreciate it. However, I cannot make it work. Tried gnome-terminal and there it's working flawlessy out of the box.

Will just stick to that for now.

Thanks again!

Offline

#11 2021-02-07 12:40:20

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

@ToZ, I would like to follow-up on this one as I really want this to work with XFCE Terminal.

It's best shown by this video:

https://drive.google.com/file/d/1-We99l … p=drivesdk

Your first suggested command breaks the terminal output + breaks my FZF search shortcut Ctrl + R.

Any ideas why?

Offline

#12 2021-02-07 19:56:59

xfceforumorg1220
Member
Registered: 2012-03-26
Posts: 19

Re: Terminal preferences: show running command in title? [solved]

There is this bug report:

'Replaces initial title' not working in xfce4-terminal 0.8.7.4 (Xfce 4.12)
https://gitlab.xfce.org/apps/xfce4-terminal/-/issues/35

Offline

#13 2021-02-07 22:01:57

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

My old method doesn't work now. However, based on the link that xfceforumorg1220's provided, I can get it to work using the following: creating a function to rename the title, running the command in the link, and changing the default title. Here is my ~/.bashrc file:

#
# ~/.bashrc
#

#function to retitle terminal windows
title () {
	export PS1="\[\e]2;$1\a\][\u@\h \W]\$ "
}

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

PS1='[\u@\h \W]\$ '

export EDITOR=vi

export PROMPT_COMMAND='history -a'
export HISTCONTROL=ignoredups
case "$TERM" in xterm*|rxvt*) 
   trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG ;; *) ;; 
esac

#set the default terminal title
title Terminal

breaks my FZF search shortcut Ctrl + R

What is FZF?

Online

#14 2021-02-08 13:08:45

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

@ToZ this works beautifully, thank you!

FZF is a very handy tool to search the history: https://github.com/junegunn/fzf

Offline

#15 2021-02-09 07:21:50

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

One last question:

I am now using below .bashrc which works great except for the fact that my prompt no longer shows the working directory but a generic BASH.

Any ideas how to fix that?

# .bashrc

# source fzf key bindings
if [ -f /usr/share/fzf/shell/key-bindings.bash ]; then
        . /usr/share/fzf/shell/key-bindings.bash
fi

# Show running command in terminal window title
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)} \w\a\]$PS1"
    trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG
    ;;
*)
    ;;
esac

tRGL8Hg.png

Last edited by orschiro (2021-02-09 11:15:27)

Offline

#16 2021-02-09 13:03:10

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

I think you need a PROMPT_COMMAND. Try this:

# .bashrc

export PROMPT_COMMAND='history -a'

# source fzf key bindings
if [ -f /usr/share/fzf/shell/key-bindings.bash ]; then
        . /usr/share/fzf/shell/key-bindings.bash
fi

# Show running command in terminal window title
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)} \w\a\]$PS1"
    trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG
    ;;
*)
    ;;
esac

Online

#17 2021-02-09 13:06:13

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

Thanks ToZ!

Unfortunately, this doesn't make any difference.

Offline

#18 2021-02-09 13:09:04

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

Hmm. It worked here on Arch. Is that the full content of your .bashrc that you posted?
Edit: Make sure you close all running windows of xfce4-terminal before you try the new .bashrc file - something is getting cached there.

Last edited by ToZ (2021-02-09 13:11:05)

Online

#19 2021-02-09 13:19:10

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

Offline

#20 2021-02-09 17:41:15

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

What does the following return?

env | grep 'PS1\|PROMPT_COMMAND'

Online

#21 2021-02-09 18:18:23

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

bash-5.0$ env | grep 'PS1\|PROMPT_COMMAND'
PROMPT_COMMAND=history -a

Offline

#22 2021-02-09 19:13:57

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

A couple of things to try:

  1. Add "export PS1" to the end of the .bashrc file

  2. comment out the FZF lines and try without it?

Do either of those work?

If not, I'm out of ideas.

Online

#23 2021-02-10 18:35:46

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

What a big bummer! These are all not working. :-(

https://drive.google.com/file/d/1FsASdK … p=drivesdk

Offline

#24 2021-02-10 18:58:30

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 7,415

Re: Terminal preferences: show running command in title? [solved]

Try this version:

# .bashrc

export PROMPT_COMMAND='history -a'

# Show running command in terminal window title
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)} \w\a\]$PS1"
    trap 'echo -ne "\033]2;$(history 1 | sed "s/^[0-9 ]* \+//")\007"' DEBUG
    ;;
*)
    ;;
esac

Online

#25 2021-02-10 19:01:02

orschiro
Member
Registered: 2017-11-30
Posts: 54

Re: Terminal preferences: show running command in title? [solved]

No difference. sad

https://drive.google.com/file/d/1Z18tge … p=drivesdk

Last edited by orschiro (2021-02-10 19:04:15)

Offline

Board footer

Powered by FluxBB