csh - simple helper for urxvt

This shell script provides quick SSH shortcuts, and displays a configurable terminal background color while connected.

csh - simple helper for urxvt
Your terminals prefer themselves in color
Originally published at dev.to

This shell script provides quick SSH shortcuts, and displays a configurable terminal background color while connected.

#!/bin/bash
#
# cssh: Color SSH helper
#
# Author: Mitch Jackson <[email protected]
# Copyright: Nah
#
# Set the terminal background color and transparency before
# making an SSH connection, then resets them when the connection closes
#
# Allows for configuring different background colors per host,
# along with connetion aliases

# background color and opacity value to use during the session
CONN_BGCOLOR="#330000"
CONN_OPACITY=85

# background color and opacity to return to after the session ends
EXIT_BGCOLOR="#000000"
EXIT_OPACITY=70

# Connection Definitions:
#
# Define a shortname for each connection below
case $1 in
  box1)
    SSH_HOST="box1.lion.land"
    ;;
  box2)
    SSH_HOST="10.0.0.2"
    CONN_BGCOLOR="#002200"
    ;;

  *) # Catch-all
    SSH_HOST="$1"
    CONN_BGCOLOR="#000333"
    ;;
esac

printf '\33]11;%s\007' "[$CONN_OPACITY]$CONN_BGCOLOR"
command ssh $SSH_HOST $2 $3 $4
printf '\33]11;%s\007' "[$EXIT_OPACITY]$EXIT_BGCOLOR"

And another simple script to set the terminal background color and opacity for the current terminal

#!/bin/bash
#
# tglow: Set terminal background and opacity
#
# Author: Mitch Jackson <[email protected]
# Copyright: Nope

function usage() {
  echo
  echo "tglow: set terminal background and opacity"
  echo
  echo "    usage: tglow 30 green"
  echo "           tglow 95 \"#333000\""
  echo
  exit 1
}

if [[ -z "$1" ]] || [[ -z "${2+x}" ]]; then
  usage
fi

printf '\33]11;%s\007' "[$1]$2"