LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   colorized ssh sessions (https://www.linuxquestions.org/questions/linux-desktop-74/colorized-ssh-sessions-4175621256/)

genese 01-09-2018 02:00 AM

colorized ssh sessions
 
Hello All,

Starting from a kde konsole, I ssh to different hosts.

I'd like to set the background with a different colors according to the host.

I have excluded the 'setterm' command because of the restricted choice of colors.

I tried to use ANSI sequences like
Code:

printf "\e[48;2;241;255;236m \n"
but

1) colorized commands like 'ls' or 'grep' reset the bg color. OK, I can disable colorization.

2) vim background is independent of the terminal background, and that is my real problem.

Any suggestion ?

ondoho 01-09-2018 02:18 AM

i think you will need to start a dedicated terminal emulator window with different settings for each ssh session.

genese 01-11-2018 11:10 PM

Opening a new terminal would certainly solve my problem, but implementation will not be easy with my current setup.

I run my desktop as an unprivileged user, open Konsoles, and then su to root.

From that point, I open ssh sessions to other hosts, jumping from one host to another, possibly returning to the first.

Hence my need of colorization ;-)

redfox2807 01-18-2018 12:25 PM

Why do you need root for openning a ssh session? You can always ssh from a regular user

ondoho 01-18-2018 02:27 PM

^ i wholeheartedly agree, but didn't mention it earlier since it didn't seem relevant for the colorization issue.

redfox2807 01-18-2018 03:17 PM

Indeed. I just was pretty surprised to read that root was needed. The best way to solve a problem is to avoid it =)

Concerning the colorozation issue:

1) On all hosts I use zsh with oh-my-zsh extension. Setting different ZSH_THEME variables in ~/.zshrc for different hosts makes the hosts easily distinguishable. No need for fore/background color changes.

2) For vim different foreground and background colors could be set in ~/.vimrc
Code:

highlight Normal ctermfg=red ctermbg=yellow

genese 01-19-2018 08:16 AM

[SOLVED]
 
Ok I managed to get colorized ssh sessions by

1) applying redfox2807 suggestion to .vimrc

2) in .bash_profile, getting colors from .vimrc and including them in the prompt (PS1)

3) viewing man pages with "view" (read only vim) instead of "less"

I expect some command breaking my display in the future, but for now I'm satisfied with this solution.

Thank you redfox2807 and ondoho for your useful comments.


All times are GMT -5. The time now is 08:51 AM.