Visual difference between local and remote terminal sessions

I use Terminal under OS X quite widely.

I find it rather annoying (and a little dangerous) that my local and remote sessions look exactly the same in the terminal. I am wondering if this is possible, perhaps through a bit of bash programming to clearly distinguish between local and remote sessions. A different background color will be a great start.

NOTE: I was not sure if you post this question here or on SuperUser. This could potentially include a bit of bash programming, and it might be of interest to many developers, so I chose Stack at the end. If you think I should move it to SU, just leave a comment ...

+4
source share
4 answers
+3
source

I was looking for a programmatic way to do this from the shell (I have many different local users, like postgres, oracle, etc.).

It looks like you can do it through AppleScript (which, given that it sits on top of the basic structure of the scripts, suggests that it should be possible to do something else).

http://www.red-sweater.com/blog/220/random-color-terminal

Some extra digging turned out like this - osascript - this is obviously command line access for AppleScript. There are several approaches listed here, but it seems like it indicates a way to programmatically change the active terminal window in the terminal (so you should be able to change the local session when you log in, if not remotely).

http://hints.macworld.com/article.php?story=20040823015557368

A third way to do this could be to end the script to open a specific color terminal for SSH sessions and create a separate icon for it.

+1
source

Here is a suggestion for Leopard and Snow Leopard (I don't have Tiger to check if it works).

  • In the terminal settings, select the "Settings" tab and create new settings with a different background and name it the remote host.
  • Click the Shell tab button, select the Run Command check box, and enter the ssh command to connect to the remote host.
  • Now you can click on the “Terminal Panel” menu (top), select “New Window” or “New Tab”, select the setting you just created.
0
source

In Terminal.app you can create a different settings value for each use, that is, a different colored background or other functions for connecting to different hosts or for launching various applications. The Profiles feature in iTerm provides a similar object, possibly easier to use or more transparent. Since you can run a script when a parameter or profile is used, any changes to the appearance of the terminal can be made by attaching the appropriate script.

Alternatively, you can set the prompt to appear differently by configuring PS1 in .bashrc or / etc / bashrc (or the local version). There's a similar question (also in Stackoverflow) in What is your favorite Bash hint? , which tells how to set the background color as well as the color of the text. I basically adjusted the color of the text in .bashrc (or basically / etc / bashrc) and set the background in the terminal settings / iTerm / profiles.

Since there are usually very few users, and we generally agree on what the Bash prompt looks like, I like to use the global settings in / etc. On some systems, the user is not recommended to modify / etc / bashrc directly, but instead gives the key to creating / etc / bash.bashrc.local or some such. Other systems do not have a global default. For systems without a global default, I create / etc / bashrc, which calls / etc / bash.bashrc.local, but hardly anything else.

And the previous answer indicated that the settings in Terminal.app work for Leopard and Snow Leopard, but were not sure about Tiger. I use this feature in Mavericks and I am sure that Lion and Mountain Lion were almost identical.

0
source

All Articles