我想通过检测来configurationterminaltypes。 例如,当我使用PuTTY连接到Solaris机箱时, $TERMvariables设置为vt100 。 我想谈谈这个,当terminal模拟器是PuTTY时,将$TERM设置为xterm 。
我注意到在^ E PuTTY回答PuTTY 。 但我认为最好的方法是使用tput来尝试检测terminal仿真器的types。 问题是我找不到任何在terminfo或tput手册中的参考如何做到这一点。
否则,我会尝试一些基于:
unset remote_term;echo $'\cE';read -rt 1 -n5 remote_term ;echo remote_term=$remote_term
也许这太简单了,但是如果你关心你的用户环境(假设每个人都有他们自己的帐户,并且没有疯狂的帐户共享进行,一堆人使用相同的用户名+密码组合)。 。
为什么不把东西添加到你自己的shell环境文件中呢?
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 SUM 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)
(上面的代码应该没有问题)
Regular Bourne(/ bin / sh)Shell(〜/ .profile)
(上面的代码,但是/ bin / sh不会做可变分割,所以TTY_DEV必须具有更多的创造性。)
你为什么不能在PuTTY中设置连接选项来协商所需的terminaltypes?
在“PuTTYconfiguration”下,单击“连接” – >“数据”,然后在“terminal详细信息”部分中将“terminaltypesstring”设置为所需的任何terminaltypes。 Mine被设置为ansi,但您可以轻松地将其更改为xterm。
这比拦截Ctrl-E应答更为优雅,因为它遵守用户对terminaltypes的意图。