Emacs has variables that describe the current hostname and username. Just like you would do in order to conditionally do something based on the hostname, you have the variable user-login-name
(from the docs: "The user's name, taken from environment variables if possible.").
So, I guess something like this would apply:
(when (string-equal user-login-name "myuser")
(load-theme 'theme1))
(when (string-equal user-login-name "commonuser")
(load-theme 'theme2))
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
Best Answer
I had the same problem.
I had modified some font settings through
describe-face
which had set values incustom-set-faces
in my .spacemacs file.This seemed to then be applying a background colour to all themes. Removing this customisation and restarting spacemacs solved the problem.