And don't say "$TERM
" – it's always xterm
.
How can a bash
script tell what terminal it's running in, specifically whether it's iTerm, Terminal.app, or actually an xterm?
I ask because reset
does not work¹ out of the box on Terminal.app and iTerm2. iTerm2, however, does recognize an escape sequence for doing a terminal reset (\x1b]50;ClearScrollback\x07
), and if I could detect it, I could override reset
with an alias that does the right thing. AFAICT, Terminal.app lacks a reset sequence, and people resort to ridiculous tom-hackery to hack around that.
My end goal here is to have reset
work the same whether I'm working on OS X or Linux, working locally or remotely through SSH. (I don't want to have to try to remember which, and it's useful to do reset && command-that-outputs-a-bunch
and have up-enter work.) Terminal.app and iTerm are throwing a wrench in this plan by not implementing reset
correctly.
This means that simply overriding reset
isn't quite it: if I'm on a Linux machine, it needs to know whether I'm using gnome-terminal
or iTerm in order to send the right escape sequence.
Is there any way (even if I need an ioctl
) to ask the terminal what it really is?
¹For the purposes of this question, reset should clear the screen, reset the cursor, and wipe the scrollback buffer.
Terminal.app
's settings, terminal tab and set scrollback lines to 0? Does that disable any and all text above the current line, or just anything above the top of the screen? I know, it's not exactly what you asked for, worth a shot.reset
, since that's what my fingers know.reset
command to clear the terminal emulator’s scroll-back content, but that’s not guaranteed to do that, because scroll-back is a terminal emulator-specific feature, not really a part of a terminal. However, Terminal supports an extension of the ED (Erase in Display) escape sequence to erase the scroll-backESC [ 3 J
. You can clear the screen, then use that, e.g.,reset && printf '\e[3J’
xterm
(throughTERM=xterm
) I'd expect that you emulate a superset of the XTerm, which clears its scrollback on reset. (Just as if you sent the escape sequence for "blue", you'd expect blue.) Granted, my xterm tells me thatErase is backspace.
, which I'm thankful nothing else does; that's just annoying.