I want to set my laptop to load an image in the shell's background or set the background color to red if I'm connected via SSH.

How can this be done? With a bash function in .bashrc?

I have: Set the prompt to different colors.

My terminal emulator is Konsole, KDE's terminal.

I tried this but it didn't load correctly, didn't see any change in the shell.

EDIT: I've managed to do it in a test but it's not the behaviour I'm looking for. The behaviour I'm looking for is to set my local system so that, when I SSH to a remote the "shell environment/shell profile" is a different one from my default, and something flashy, like red background or an image.

Here is how:
This will set the background to red and text to black.

It's on Debian Wheezy and there was no .bash_profile file, so create that. And in it copy/paste this there:

if [ ! -z "$SSH_CONNECTION" ] ; then
    source ~/Scripts/.shell_ssh_bashrc  ## This file contains the command to execute if it's an SSH session.

Create a custom bashrc file for use if this is SSH session(remote shell) And copy/paste this there:

setterm -term linux -back red -fore black -clear

This would mean that I would have to make this configuration on all the remote's.

  • what about using PROMPT_COMMAND with a function that checks if the parent pids list is running SSH? – Aquarius Power Aug 31 '14 at 23:06
  • @AquariusPower If no one has an answer, I'll look into that, thanks. – somethingSomething Aug 31 '14 at 23:30
  • 1
    As far as I'm aware, Konsole uses the current profile selection for ssh. You may be able to change your bashrc to alias ssh to a script that changes the current profile. This is the only solution that I can think of. – Steven Walton Sep 1 '14 at 1:31
  • 1
    At least xterm has escape sequences to set the default colours (including the default background colour). For example, echo -e '\e]11;Yellow\a' will instantly set your background to Yellow. Gnome-terminal doesn't seem to support this, but maybe konsole does? – celtschk Sep 1 '14 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.