In Emacs no window mode, the background is automatically the same as the terminal (gnome-terminal). When I look at (frame-parameters) I see that (background-color . "unspecified-bg"). Well, for me, the background happens to be black. Is there a way to find out what the actual background color is for an Emacs session?
1 Answer
If you know how to find out from the terminal, you can use that selfsame command to find out from Emacs.
In my case, I'd make a script like this:
#!/bin/zsh
cat .Xresources | grep 'URxvt\*background\:' | cut -d" " -f2
(Note: -d is to set the field delimiter, -f is to set what field is to be shown: the first field is 1, not 0)
The command looks the way it does because .Xresources, the file that sets the background color, looks like this:
# ...
URxvt*background: black
# ...
Make the script executable (chmod +x), and put it in your PATH (echo $PATH).
If the script is called what_bg, in Emacs, M-x shell-command RET what_bg.
Edit (in response to comment):
See if this works. I tested it from Emacs, and in urxvt, xterm, and rxvt. While it is more portable than the first script, it assumes .Xresources configuration (which is, while not uncommon, obviously not everywhere).
I'm starting to wonder, though, why you need this to begin with?
And, if you indeed need it, can't you just look on the window to determine its color?
Anyway, the script:
#!/bin/zsh
terminal_emulator_parents=`pstree -As $$`
tep_list=`echo $terminal_emulator_parents | tr -s "-" | tr "-" " " \
| tac -s' ' | tr '\n' ' '`
found="false"
for process in `echo $tep_list`; do
if [[ $process =~ ("urxvt"|"xterm"|"rxvt") ]]; then # here: add all
found="true" # terminal emulators
break # configurable
fi # (and *configured*)
done # in ~/.Xresources
if [[ $found == "true" ]]; then
echo -n "$process: "
cat ~/.Xresources | grep -ie ^$process'\*background\:' \
| tr -s " " | cut -d" " -f2
else
echo "Couldn't determine the terminal emulator."
fi
-
I guess this is as close as I'll get for now. I was hoping to find something a little more cross-platform, but this is unix.stackexchange...
shell-commandis new to me so that's a good find.Jeff– Jeff2013-03-08 17:10:48 +00:00Commented Mar 8, 2013 at 17:10 -
1@Jeff: Made an edit; take a look.Emanuel Berg– Emanuel Berg2013-03-09 10:11:07 +00:00Commented Mar 9, 2013 at 10:11
gconftool...