Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1554  / 1 Year ago, sun, april 16, 2023, 3:34:39

I found this command to change the background color to back:


echo -ne 'e]11;#000000e' 

So, how to I make it to change the default again?


Thanks :3


More From » bash

 Answers
5

The idea is to replace the #000000 with the color of your choice. If "default" is white, you could run


echo -ne 'e]11;#ffffffe'


Now since OP wants it in a bash script, I adapted the script by blueyed available here https://gist.github.com/blueyed/c8470c2aad3381c33ea3


#!/bin/sh
# Query a property from the terminal, e.g. background color.
#
# XTerm Operating System Commands
# "ESC ] Ps;Pt ST"
#
# Source:
# Adapted from https://gist.github.com/blueyed/c8470c2aad3381c33ea3
# Posted at:
# https://stackoverflow.com/questions/2507337/how-to-determine-a-terminals-background-color#7767891
#

# save stty
oldstty=$(stty -g)

# Such that no input is needed for the read command:
stty raw -echo min 0 time 0

#11 for background color
printf "033]11;?033"

# xterm needs the sleep
sleep 0.1
read -r answer

# Change background color for #fff000 (as an example)
printf "033]11;#fff000033"

# Do your stuff on yellow background
# Here for purpose of demonstration just sleep
sleep 1
#
#
#

# Restore background-color.
printf "033$answer"

# Restore stty
stty $oldstty

You can then put your actual code in this script and modify the custom bg color (here yellow) and the sleep times etc. I tested it only on gnome-terminal.


[#423] Monday, April 17, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
atelti

Total Points: 194
Total Questions: 129
Total Answers: 110

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
atelti questions
Fri, Aug 26, 22, 02:44, 2 Years ago
Sat, Dec 10, 22, 21:37, 1 Year ago
Sat, Apr 9, 22, 13:57, 2 Years ago
;