You are not logged in.
Hi guys,
Question about this setting:
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
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.
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
Thanks. I added your line and launched a new terminal window but it's not doing the trick. See below.
Offline
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"
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
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
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.
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
- 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
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.
Offline
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).
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
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
@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
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
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?
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
@ToZ this works beautifully, thank you!
FZF is a very handy tool to search the history: https://github.com/junegunn/fzf
Offline
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
Last edited by orschiro (2021-02-09 11:15:27)
Offline
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
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
Thanks ToZ!
Unfortunately, this doesn't make any difference.
Offline
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)
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
Yes! Strange, check this:
Offline
What does the following return?
env | grep 'PS1\|PROMPT_COMMAND'
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
bash-5.0$ env | grep 'PS1\|PROMPT_COMMAND'
PROMPT_COMMAND=history -a
Offline
A couple of things to try:
Add "export PS1" to the end of the .bashrc file
comment out the FZF lines and try without it?
Do either of those work?
If not, I'm out of ideas.
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
What a big bummer! These are all not working. :-(
Offline
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
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
No difference.
https://drive.google.com/file/d/1Z18tge … p=drivesdk
Last edited by orschiro (2021-02-10 19:04:15)
Offline
[ Generated in 0.013 seconds, 7 queries executed - Memory usage: 643.83 KiB (Peak: 676.67 KiB) ]