Change background color of tmux pane depending on remote hostname

陌路散爱 提交于 2020-01-25 10:42:06

问题


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?

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?

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?


回答1:


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


来源:https://stackoverflow.com/questions/57186998/change-background-color-of-tmux-pane-depending-on-remote-hostname

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!