根据远程主机名更改tmux窗格的背景颜色 [英] Change background color of tmux pane depending on remote hostname

查看:270
本文介绍了根据远程主机名更改tmux窗格的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在单个窗格中从tmux SSH到远程服务器,是否可以根据服务器名称更改窗格的背景颜色?

If I ssh into a remote server from tmux in a single pane, is it possible to change the background color of the pane based on the server name?

假设我所有的生产服务器都以prod_XYZ开头,而开发服务器以dev_XYZ.开头.如果我将这两个服务器ssh放入,是否可以根据我所使用的服务器类型对它们进行不同的着色?也就是说,基于服务器的前缀吗?

Let's say all my prod servers start with prod_XYZ and a dev server starts with dev_XYZ. If I ssh into these two servers, can I color them differently based on the type of server I am on? That is, based on the server prefix?

我知道tmux窗格现在了解颜色.因此,如果可以检测到正在使用ssh命令,则可以确定服务器的名称,然后将命令select-pane -t:.1 -P 'fg=blue,bg=red'发送到tmux.但是,我如何(A)将颜色发送到正确的窗格; (B)从终端获取服务器名称以颜色tmux?

I know tmux panes now understand color. So if I can detect the ssh command is being used then I can figure the name of the server and send the command select-pane -t:.1 -P 'fg=blue,bg=red' to tmux. But how do I (A) send the color to the correct pane; (B) get the server name from the terminal to color tmux?

推荐答案

最简单的方法是编写脚本或shell函数,然后将其别名为ssh,例如(未经测试):

The easiest way is to write a script or shell function and then alias it to ssh, something like (not tested):

#!/bin/sh
if [ -n "$TMUX" ]; then
    case "$1" in
    prod_*)
        tmux selectp -P bg=red
    ;;
    esac
fi
ssh "$@"
tmux selectp -P default

这篇关于根据远程主机名更改tmux窗格的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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