It sounds to me like you want to check whether or not there is a X server to connect to.
Something like:
if [ -n "$DISPLAY" ]; then
: X
else
: no X
fi
The TERM
environment variable is a way that you, the user,
can tell programs (e.g., emacs
, grep
, less
, ls
, and vim
)
what kind of terminal they are running on, so they will know its parameters, including what capabilities it has and what escape sequences they need to issue to access them. This exists because it’s too hard, in general,
for the software to determine this for itself
(and was pretty much impossible when users interfaced
with computers through terminals that were external,
and only connected to the computer by a data cable).
gnome-terminal
is a program that provides terminal-like services
to the user and the programs that the user runs within the terminal.
gnome-terminal
may be aware of environment variables
that were set in its environment,
before it was invoked (DISPLAY
being the obvious example),
but it has no knowledge of environment variables that are set
in in the processes that are running under it.
So, gnome-terminal
has whatever capabilities it has.
It may be possible to adjust/constrain these externally,
e.g., through command-line options, the pre-existing environment,
configuration files, and dialogs in the window frame,
but not by changing TERM
in the shell in the window.
If it’s capable of displaying 256 colors,
then it’s capable of displaying 256 colors,
and you will be able to cause it to do so
by sending it the appropriate escape sequences.
But, as long as you have TERM
set to xterm
,
the programs that you run will believe that you are telling them
that they are running in an eight-color-capable terminal,
and so they will restrict their requests (escape sequences)
to those capabilities.
You need to set TERM
to xterm-256color
,
not to enable gnome-terminal
to display 256 colors,
but to tell programs like grep
and ls
to ask it
to use more than 8 colors.
Best Answer
There's nothing built in, exactly, but there are two ways to get at the scrollback text.
You can configure the
XTerm.vt100.on4Clicks
andXTerm.vt100.on5Clicks
resources (or fromon1Clicks
onwards, for that matter) to choose to copy the whole scrollback to the X11 PRIMARY selection. For example, to copy the whole scrollback on a quadruple click, put this line in your.Xresources
:You'll then have to arrange your own method for bringing up some way to search the content of the X selection, such as opening an editor or a pager with a window manager binding.
You can call the
print-everything
action to send the whole scrollback to a program determined by theXTerm.vt100.printerCommand
resource. For example, to open the scrollback in less (running in a new xterm) when you press Ctrl+/, put these lines in your.Xresources
: