SSH到特定服务器时如何使Apple终端窗口自动更改配色方案 [英] How do I make the apple terminal window auto change colour scheme when I ssh to a specific server

查看:159
本文介绍了SSH到特定服务器时如何使Apple终端窗口自动更改配色方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我切换到远程生产服务器时,我希望终端窗口的配色方案更改为明亮而令人恐惧的某种颜色,最好是红色,以警告我我正在触摸动态的令人恐惧的服务器.

When I ssh into a remote production server I would like the colour scheme of my terminal window to change to something brigh and scary, preferably red, to warn me that I am touching a live scary server.

如何使其自动检测到我在某处进行过换色,并且如果该处在特定列表中,请更改配色方案?

How can I make it automatically detect that I have ssh'ed somewhere, and if that somewhere is on a specific list, change the colour scheme?

我想更新Terminal.app的Scheme,不知道我将如何在纯linux/unix env中做到这一点

I want to update the Scheme of Terminal.app, not know how I would do this in a pure linux/unix env

推荐答案

~/bin/ssh中放置以下脚本(确保~/bin/在PATH中/usr/bin/之前):

Put following script in ~/bin/ssh (ensure ~/bin/ looked before /usr/bin/ in your PATH):

#!/bin/sh

HOSTNAME=`echo $@ | sed s/.*@//`

set_bg () {
  osascript -e "tell application \"Terminal\" to set background color of window 1 to $1"
}

on_exit () {
  set_bg "{0, 0, 0, 50000}"
}
trap on_exit EXIT

case $HOSTNAME in
  production1|production2|production3) set_bg "{45000, 0, 0, 50000}" ;;
  *) set_bg "{0, 45000, 0, 50000}" ;;
esac

/usr/bin/ssh "$@"

上面的脚本从"username @ host"行中提取主机名(假定您使用"ssh user @ host"登录到远程主机).

The script above extracts host name from line "username@host" (it assumes you login to remote hosts with "ssh user@host").

然后根据主机名设置红色背景(对于生产服务器)或绿色背景(对于所有其他背景).结果,您所有的ssh窗口都将带有彩色背景.

Then depending on host name it either sets red background (for production servers) or green background (for all other). As a result all your ssh windows will be with colored background.

我假设这里的默认背景是黑色,所以当您从远程服务器注销时,脚本会将背景颜色恢复为黑色(请参阅"trap on_exit").

I assume here your default background is black, so script reverts the background color back to black when you logout from remote server (see "trap on_exit").

请注意,但是此脚本不会跟踪从一台主机到另一台主机的ssh登录链.因此,如果您先登录到测试服务器,然后从中登录到生产服务器,则背景将变为绿色.

Please, note however this script does not track chain of ssh logins from one host to another. As a result the background will be green in case you login to testing server first, then login to production from it.

这篇关于SSH到特定服务器时如何使Apple终端窗口自动更改配色方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆