#!/bin/bash ## Bash script under the GPL license. ## Question / patch : laurent_defert at yahoo fr ## Description: This script allows to change the background pixmap of the current terminal emulator ## when an ssh command is issued. So you can have a nice pixmap displayed that changes depending ## on which computer you are. ## Usage: put your pixmaps in $XPM_PATH, and name them with the following pattern: ## * hostname.xpm -> xpm specific of the hostname ## * user@hostname.xpm -> xpm specific of the username/hostname ## * user@hostname:port.xpm -> ... ## then you can use this script instead of ssh to establish the connection to the remote host ## After the ssh session, the background $XPM_PATH/default.xpm is set back (or it's to none if it dosn't exists) XPM_PATH="/home/lds/.termbg" # Parse arguments # Hostname HN="" # Port PT="" # Username UN="" # Run in background BG="0" for ((i=1;i<=${#};i++)) do if [ "${!i:0:1}" == "-" ] then if [[ "${!i}" == "-f" || "${!i}" == "-n" ]] then BG="1" break fi if [[ "${!i}" == "-l" ]] then ((i++)) UN="${!i}" continue fi if [[ "${!i}" == "-p" ]] then ((i++)) PT="${!i}" continue fi # if this option takes a value, then skip the next argument a="${!i}" if [[ "$a" == "-b" || "$a" == "-c" || "$a" == "-D" || "$a" == "-e" \ || "$a" == "-F" || "$a" == "-i" || "$a" == "-L" || "$a" == "-l" \ || "$a" == "-m" || "$a" == "-o" || "$a" == "-p" || "$a" == "-R" \ || "$a" == "-S" || "$a" == "-w" ]] then ((i++)) fi else HN=${!i} fi done if [[ "$BG" == "1" || "$HN" == "" ]] then exec ssh "$@" fi ## Retrieve the username if the hostname is in the form user@hostname if [ "$UN" == "" ] then ## Dirty, if there is a way not to use grep here, ## send a patch! if [ "$(echo $HN|grep @)" != "" ] then UN=${HN/@*/} HN=${HN/*@/} fi fi #echo User: $UN #echo Host: $HN #echo Port: $PT #echo Bgd : $BG XPM="" if [[ "$UN" != "" && "$PT" != "" ]] then if [ -e "$XPM_PATH/$UN@$HN:$PTi.xpm" ] then XPM="$XPM_PATH/$UN@$HN:$PT.xpm" fi fi if [[ "$XPM" == "" && "$UN" == "" && "$PT" != "" ]] then if [ -e "$XPM_PATH/$HN:$PT.xpm" ] then XPM="$XPM_PATH/$HN:$PT.xpm" fi fi if [[ "$XPM" == "" && "$UN" != "" && "$PT" == "" ]] then if [ -e "$XPM_PATH/$UN@$HN.xpm" ] then XPM="$XPM_PATH/$UN@$HN.xpm" fi fi if [ "$XPM" == "" ] then if [ -e "$XPM_PATH/$HN.xpm" ] then XPM="$XPM_PATH/$HN.xpm" fi fi #echo background: $XPM if [ "$XPM" != "" ] then echo $'\033'\]20\;$XPM\;100$'\007' fi ssh $@ if [ "$XPM" != "" ] then echo $'\033'\]20\;$XPM_PATH/default.xpm$'\007' fi