Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2640  / 2 Years ago, fri, march 18, 2022, 7:04:16

I'd like the title of my terminal windows to show the last command that ran. It'd be handy for finding the terminal that's running Mongrel in Dev/Test/Prod etc (for testing rails apps).



I tried this code:



if [ "$SHELL" = '/bin/bash' ]
then
case $TERM in
rxvt|*term)
set -o functrace
trap 'echo -ne "e]0;$BASH_COMMAND007"' DEBUG
# export PS1="e]0;$TERM007$PS1"
;;
esac
fi


At least, I think that's the code that I tried. It did work, but it caused some strange behavior, like window titles that would get stuck in a loop until I hit Ctrl C when changing directory to a symlink.



What's a reliable way to set my window title to the last command that was run?


More From » bash

 Answers
4

You can also use the xtitle tool:



sudo apt-get install xtitle
lastcmd() { xtitle $(history 1 | cut -c8-); }
PROMPT_COMMAND=lastcmd

[#40960] Saturday, March 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oileweaty

Total Points: 337
Total Questions: 108
Total Answers: 105

Location: Western Sahara
Member since Mon, May 3, 2021
3 Years ago
oileweaty questions
Thu, Jul 1, 21, 01:57, 3 Years ago
Wed, Nov 24, 21, 11:48, 2 Years ago
Sat, May 14, 22, 00:50, 2 Years ago
;