Score:0

Complete procedure for changing the background color to a different color for each different host

cn flag

I am looking for a clear explanation on how to change the background color on a terminal depending on the host that is being ssh'ed into. Preferable requiring only local changes (but I will take a solution requiring altering something like .bashrc in every host if it is the only way). Ideally the color refers back to normal upon exiting. The method should also not disrupt rsync (see https://unix.stackexchange.com/questions/331429/how-to-automatically-change-terminal-background-based-on-ssh-hostname and http://serverfault.com/questions/267154/protocol-version-mismatch-is-your-shell-clean).

A partial solution can be found here https://serverfault.com/questions/130436/how-can-i-automatically-change-terminal-colors-when-i-ssh-a-server but it requires AppleScript.

A partial solution seems to be available here, but it doesn't describe a clear enough procedure for me to reproduce and apparently it breaks rsync.

Relevant information can also be found in https://superuser.com/questions/347512/can-i-have-my-terminal-background-change-based-on-hostname.

Organic Marble avatar
us flag
Also https://askubuntu.com/q/13705/243321
cn flag
If anything breaks `rsync` then that's because the remote shell _unconditionally_ outputs something, probably from `.profile`, `.bash_profile`, `.bashrc` or alike. The solution is to make it conditional to the output going to a _terminal_, i.e. `if [ -t 1 ]; then ...; fi`. Alternatively, make it conditional to the shell being an _interactive_ one.
cn flag
Quite a few terminal emulators, including `gnome-terminal` which you tagged the question with, supports the OSC 11 escape sequence to change the default background color (but do so retroactively for earlier output, too, which might be confusing). E.g. `printf '\e]11;#abcdef\e\\'`. Reset with OSC 111 `printf '\e]111\e\\'`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.