You can do this if you use a function that checks whether $BASH_COMMAND
is set and prints your CWD if it is not. Add these lines to your ~/.bashrc
:
trap 'echo -ne "\033]0;$BASH_COMMAND\007"' DEBUG
function show_name(){
if [[ -n "$BASH_COMMAND" ]];
then
echo -en "\033]0;`pwd`\007";
else
echo -en "\033]0;$BASH_COMMAND\007";
fi
}
export PROMPT_COMMAND='show_name'
This will cause your terminal's name to be the currently running command (if there is one) or your current directory if there is not. Bear in mind that this will result in a slightly schizophrenic terminal if you run a long loop that runs a command many times. Try it with while true; do echo foo; done
for example.
If you are using zsh
this is much easier to achieve (source) and it handles loops correctly:
case $TERM in
xterm*)
preexec () {
print -Pn "\e]0;$*\a"
}
;;
esac
What is $TERM
for?
The $TERM
variable is for use by applications to take advantage of capabilities of that terminal.
For example, if a program want's to display colored text, it must first find out if the terminal you're using supports colored text, and then if it does, how to do colored text.
The way this works is that the system keeps a library of known terminals and their capabilities. On most systems this is in /usr/share/terminfo
(there's also termcap, but it's legacy not used much any more).
So lets say you have a program that wants to display red text. It basically makes a call to the terminfo library that says "give me the sequence of bytes I have to send for red text for the xterm terminal". Then it just takes those bytes and prints them out.
You can try this yourself by doing tput setf 4; echo hi
. This will get the setf
terminfo capability and pass it a parameter of 4
, which is the color you want.
Why gnome terminal lies about itself:
Now lets say you have some shiny new terminal emulator that was just released, and the system's terminfo library doesn't have a definition for it yet. When your application goes to look up how to do something, it will fail because the terminal isn't known.
The way your terminal gets around this is by lying about who it is. So your gnome terminal is saying "I'm xterm".
Xterm is a very basic terminal that has been around since the dawn of X11, and thus most terminal emulators support what it supports. So by gnome terminal saying it's an xterm, it's more likely to have a definition in the terminfo library.
The downside to lying about your terminal type is that the terminal might actually support a lot more than xterm does (for example, many new terminals support 256 colors, while older terminals only supported 16). So you have a tradeoff, get more features, or have more compatibility. Most terminals will opt for more compatibility, and thus choose to advertise themselves as xterm
.
If you want to override this, many terminals will offer some way of configuring the behavior. But you can also just do export TERM=gnome-terminal
.
Best Answer
You can enable mouse position reporting on an X11 terminal emulator, but you need a co-operating application to read the position and act on it. The terminal doesn't do it on its own.
nano
obviously does it, and so do other screen-oriented applications (e.g.links
).If you're just using the command-line, this won't be very useful unless you have a mouse-tracking version of
libreadline
. Even then, I suspect that moving your hand off the keyboard, moving a mouse/using a trackpad, then moving back to the keyboard is slower than Meta-B or Ctrl-A.Here's a very long list of various terminal directives, including mouse tracking on various terminal emulators.