#!/bin/bash # # bash script to set screen settings per-host (useful for a shared # home directory, where you only have one .screenrc) # # Copyright Dave Dillow 11 Oct 2008 # Feel free to use this under the GPLv2 license. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # # To use this, put this somewhere reachable, and add the # following line to your .bashrc: # type screen &> /dev/null && source /path/to/this/file # __screen_cleanup() { local i for (( i = 0; i < ${#__screen_cleanup_list[@]}; i++)); do eval "unset ${__screen_cleanup_list[i]}" done unset __screen_cleanup_list __screen_cleanup } __screen_add_cleanup() { __screen_cleanup_list[${#__screen_cleanup_list[@]}]=$1 } __screen_add_cleanup __screen_add_cleanup __screen_cmd() { screen ${config} -d -r ${STY} -X "$@" &> /dev/null } __screen_add_cleanup __screen_cmd __screen_fixup() { local config session caption host hs hostfunc [[ ${SCREENRC} ]] && config="-c '${SCREENRC}'" host=${HOSTNAME%%.*} session=${STY#*.} session=${session%.${host}} hs=$(echo -ne "[${session} %n: %t] %h") # Put your favorite caption line in here, and allow yourself # keywords to substitute per host # caption="%{= BASE}[%H ${session}] " caption="${caption}%L=%?%-Lw%?%{FOCUS}%50L>%n%f %t" caption="${caption}%{= BASE}%?%+Lw%?%-0<" hostfunc=__screen_host_${HOSTNAME//./_} [[ $(type -t $hostfunc 2>/dev/null ) == "function" ]] || hostfunc=__screen_host_default eval "$hostfunc" __screen_cmd defhstatus "${hs}" __screen_cmd hardstatus string "${hs}" __screen_cmd caption string "${caption}" # Let new shells know we've been setup # __screen_cmd setenv SCREEN_FIX_HOST ${HOSTNAME} export SCREEN_FIX_HOST=${HOSTNAME} } __screen_add_cleanup __screen_fixup # Define your per-host entries here # # You can fixup ${hs} and ${caption}, and do other commands # as needed for this particular host # # Add a __screen_add_cleanup line for each function you add # # Colors (capital letter is the sumbol for that color): # blacK Red Green Yellow Blue Magenta Cyan White Default # . for unchanged # # Attributes: # Underline Bold Reverse Standout # # Put a space between attributes and the color specification # Color spec is background, then foreground # __screen_host_default() { caption=${caption//BASE/gk} caption=${caption//FOCUS/yk} } __screen_add_cleanup __screen_host_default __screen_host_home_example_org() { caption=${caption//BASE/bw} caption=${caption//FOCUS/rw} # Set the escape to ^B __screen_cmd defescape $'\002'b __screen_cmd escape $'\002'b } __screen_add_cleanup __screen_host_home_example_org [[ ${STY} && ${SCREEN_FIX_HOST} != ${HOSTNAME} ]] && __screen_fixup __screen_cleanup