1

In the thread below

Programmatic access to current xterm background color?

Alex North-Keys provides a useful bash script that returns the background color of the current xterm. I'd like to use the output of this script to reset the background color after it has been changed (e.g., after logging into a remote system).

For example, his script might return something like

rgb:e0e0/ffff/ffff

Unfortunately the escape sequence I use to set the background color

echo -ne "\033]11;!*\007"

seems to work only if I feed it a named color, like ivory.

Is there a way to modify this command so that it will take as an argument something like e0e0/ffff/ffff?

Thanks!

Leo Simon
  • 111

1 Answers1

0

Copy & paste into Emacs or Vim. Delete #????? beginning one of the lines. In the line is a sed statement which contains "^[". This is text of 2 characters which needs to be replaced with one character ESC (^[). In Vim, enter C+v ESC. In Emacs, enter C+q ESC.

# filename: OSC_11_Pt_ST.sh
echo -e "\e[7m Reverse the FG/BG colors on this terminal as a visual aid. \e[0m"
y='\' # Add to end of $result (\e]11;rgb:??/??/??\e) to complete ST terminating
# OSC sequence.
# Query the background color using ST (string terminate) vice BEL (^G).Replies
# with a control sequence in RGB specification format using same terminator as
# the query (in this case, ST): "^[]11;rgb:4242/2525/5353^[\" (see file
# ctlseqs.txt). "^[" is ESC (\e); "^[]" is OSC; "^[\" is ST.
echo -en "\e]11;?\e\\"
# Read line from the standard input & assign to variable CSPEC (color specifi-
# cation as indicated by ctlseqs.txt). Do not echo input coming from terminal
# (-s); raw (-r); delimiter \ (-d).
read -s -r -d '\' CSPEC
#?????result=$(echo $CSPEC | sed 's/^[/\\\e/g')
# Set BG to "WebGrey" (decimal 128 128 128).
echo 'Set BG to "Webgrey" in 5 seconds...'
sleep 5
echo -en "\e]11;rgb:80/80/80\007"
echo "Return to original BG ($result$y) in 5 seconds..."
sleep 5
echo -en "$result$y"