0

I often work with 3 machines at the same time, several sessions on X, several on Y, and Z is my local machine so obviously some sessions there - all sitting around in a terminal windows / tabs.

The thing is, I often confuse my local machine with some remote one, and this leads to amusing but occasionally somewhat tragic results.

I would like to have strong visual cues, which are triggered automatically by me logging in to a different machine, for which machine I am on, or at least cues which differ significantly for different machines.

So far I've been manually switching the color scheme for remote hosts (using Konsole), but that's: 1. manual and 2. doesn't distinguish between different hosts. And 1. manual, that's the most annoying part. If you forget to make this setting, you get a false sense of security.

Notes:

  • I already have PS1 spelling out the hostname, I need something more eye-catching than that.
  • Any reasonable heuristic for deciding when I've switchined hosts is fine, and you may assume I only use ssh if that helps.
  • Solutions which also support SSHing-within-SSHing are quite welcome.
  • I'm particularly (but not exclusively) interested in terminal emulator apps which let you control not just the backround as a solid color, but also have some image floating somewhere, or change the color of the session bar / window title bar, or other kinds of bells and whistles. Actually, something with actual bells and whistles would probably do the trick :-)
3
  • Adjusting the prompt (PS1) using colours and/or host specific strings in the .rc of the shell is the common way to avoid such disasters. Actually, it's not ultimate safety either. Not su-ing to root anywhere but using own id's and starting everything sensitive via sudo, having DIFFERENT passwords on all hosts (it's a must anyway, isn't it?) would really stop you from starting sudo ugly_command on X while you wanted it to run on Y.
    – user556625
    May 13, 2016 at 8:56
  • Also, echoing the right ansi color sequences (echo -e '...') in the .rc can set the background of the session. Just give this a try: echo -e "\e[44m"; clear Then see this: en.wikipedia.org/wiki/ANSI_escape_code#Colors
    – user556625
    May 13, 2016 at 9:09
  • @GombaiSándor: I'm working as non-root everywhere anyway (most places I don't even have root access), so that's not much help. Coloring my prompt using escapess in PS1 might be useful I suppose. If you make an answer of it with an example you have an upvote :-)
    – einpoklum
    May 13, 2016 at 9:15

2 Answers 2

1

Take a look at Terminix. It includes features such as, quoting their homepage: "Automatic (triggered) profile switches based on hostname and directory".

(Or iTerm2 if you're on Mac, however, you using Konsole at the moments suggests it's probably not the case.)

0

My basic prompt:

$ echo $PS1
\u@\h\w\$

If I want the host to be green, I pick out the escape sequence of green from the ansi color list (\e[32m) and prepend the sequence of host (\h) with that and put the sequence of reset ([0m) so that other parts be with normal characters. Hence, my new PS1 is

export PS1='\u@\e[32m\h\e[0m\w\$ '

Putting it into my .bashrc would result in my choice of prompt at that host.

If I should want more, let's say my background to be cyan, then I would set the background sequence with an echo command and then just clear the screen:

echo -e '\e[46m'; clear

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .