4

I would like to configure the terminal type by detecting it. For example when I am connecting to a Solaris box with PuTTY, the $TERM variable is set to vt100. I would like to negotiate this so, when the terminal emulator is PuTTY, to set $TERM to xterm.

I've noticed that at ^E PuTTY answers back with PuTTY. But I think that the best method is to use tput to try to detect the terminal emulator type. The problem is that I could not find any reference in the terminfo or tput manual how to do this.

Otherwise I will try with something based on:

unset remote_term;echo $'\cE';read -rt 1 -n5 remote_term ;echo remote_term=$remote_term
Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80

2 Answers2

1

Any reason why you can't just set the connection options in PuTTY to negotiate the desired terminal type?

Under PuTTY configuration, Click Connection -> Data, and then set the "Terminal-type string" in the Terminal Details section to whatever terminal type you want. Mine is set to ansi but you can easily change that to xterm.

This is more elegant than intercepting the Ctrl-E answerback as it respects the user's intent for the terminal type.

1

Perhaps this is too simple, but if you're concerned about your user-environment (and assuming everyone has their own account, and there's no crazy account-sharing going on where a bunch of people use the same username+password combo)...

Why not just add something into your own shell's environment file?

Korn (/bin/ksh) Shell (~/.kshrc)

##############################################################################
## TERM control - if we're on the console, fix it up.
TTY=` /usr/bin/tty ` # Really should call /bin/tty in HP-UX in case of S.U.M.
TTY_DEV=${TTY##*/dev/}
if [[ ${TTY_DEV} = "console" ]]; then
## Most serial-line consoles report "/dev/console" when you use 'tty'
## Since most consoles don't set their columns and rows, resulting in weird
##   stuff when we open things like 'vi', we call 'resize' (if it's present)
   if [[ -x /usr/openwin/bin/resize   ]]; then
      printf "Console...\c"
      export PATH=${PATH}:/usr/openwin/bin && \
      /usr/openwin/bin/resize >/dev/null 2>&1 && \
      printf "fixed. \n" || \
      printf "something's broke.\n"
   elif [[ -x /usr/bin/X11/resize     ]]; then
      printf "Console..."
      export PATH=${PATH}:/usr/bin/X11 && \
      /usr/bin/X11/resize >/dev/null 2>&1 && \
      printf "fixed. \n" || \
      printf "something's broke.\n"
   else
      printf "No resize binary found, check console settings.\n"
   fi
else
   TERM=xterm
fi

Bourne Again (/bin/bash) Shell (~/.bashrc ~/.bash_profile)

(The above code should work without a problem)

Regular Bourne (/bin/sh) Shell (~/.profile)

(The above code, but /bin/sh doesn't do variable-splitting, so TTY_DEV will have to get more creative.)

Signal15
  • 943
  • 7
  • 27