* can zsh set background color?
@ 2005-01-04 15:18 Timothy Luoma
2005-01-04 15:20 ` Mads Martin Joergensen
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Timothy Luoma @ 2005-01-04 15:18 UTC (permalink / raw)
To: zsh-users
I don't suspect this is possible, but I thought I'd ask.
Is there any way for zsh to set the background color of my terminal
program?
I'm often logged into to 3 different computers (ssh), and it would be
handy to be able to quickly look for the color of one to know that it
was the one where I was connected to X
TjL
Zsh 4.1.1 on Mac OS X
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-04 15:18 can zsh set background color? Timothy Luoma
@ 2005-01-04 15:20 ` Mads Martin Joergensen
2005-01-04 17:12 ` Timothy Luoma
2005-01-04 16:55 ` Bart Schaefer
2005-01-05 3:50 ` Drew Perttula
2 siblings, 1 reply; 11+ messages in thread
From: Mads Martin Joergensen @ 2005-01-04 15:20 UTC (permalink / raw)
To: zsh-users
* Timothy Luoma <lists@tntluoma.com> [Jan 04. 2005 16:18]:
>
> I don't suspect this is possible, but I thought I'd ask.
>
> Is there any way for zsh to set the background color of my terminal
> program?
>
> I'm often logged into to 3 different computers (ssh), and it would be
> handy to be able to quickly look for the color of one to know that it
> was the one where I was connected to X
I've the following .termcolors file which I source in .zshrc. It makes
it easy to do such. Be careful to get the escape codes right.
http://mmj.dk/conffiles/termcolors
--
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?"
-- A. P. J.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-04 15:18 can zsh set background color? Timothy Luoma
2005-01-04 15:20 ` Mads Martin Joergensen
@ 2005-01-04 16:55 ` Bart Schaefer
2005-01-04 17:04 ` Timothy Luoma
2005-01-05 3:50 ` Drew Perttula
2 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2005-01-04 16:55 UTC (permalink / raw)
To: Timothy Luoma; +Cc: zsh-users
On Tue, 4 Jan 2005, Timothy Luoma wrote:
> Is there any way for zsh to set the background color of my terminal
> program?
Depends on what the program is, but probably not. From the shell you can
set the attributes of the text that is displayed (which is what MMJ is
getting at in his reply) but not the color of the entire terminal.
> I'm often logged into to 3 different computers (ssh), and it would be
> handy to be able to quickly look for the color of one to know that it
> was the one where I was connected to X
[I wrote everything that follows while thinking "connected to X" meant
"connected using an X11 terminal emulator", but now I think it means "to
the host named X" so this may all be irrelevant. Having written it down,
though, I'm going to send it anyway.]
This is really an X11 question, and it depends on how you run your
terminal emulators, but I'll do my best to turn it into a zsh question
anyway. Let's assume xterm for discussion.
If you run xterm locally and invoke the remote login from xterm, then you
have to do something like this:
---- 8< ----
typeset -A xterm_colors
xterm_colors=( host1 red
host2 blue
host3 green )
function xterm {
setopt localoptions extendedglob noksharrays nokshglob
# Fast crude command line parsing here, could be better
if [[ " $*" = [[:space:]]-(fg|foreground) ]]
then
command xterm "$@"
else
local rshell='(ssh|rlogin|telnet)'
local userpat='(|*@|-l[[:space:]][^[:space:]]#[[:space:]])'
local remotepat="* -e ${rshell} ${userpat}(#b)([^[:space:]@]#)*"
local color=white
if [[ " $*" = ${~remotepat} && -n "${xterm_colors[${match[1]}]}" ]]
then
color=${xterm_colors[${match[1]}]}
fi
command xterm -fg $color "$@"
fi
}
---- 8< ----
However, if you instead run "xon host xterm ..." or the equivalent, then
you can just put an appropriate X resource file, e.g. one named XTerm, in
your home directory on the remote machine, and set the foreground color in
that file.
(Unless you have the same NFS-mounted home directory everywhere, in which
case you're back to the first plan.)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-04 16:55 ` Bart Schaefer
@ 2005-01-04 17:04 ` Timothy Luoma
0 siblings, 0 replies; 11+ messages in thread
From: Timothy Luoma @ 2005-01-04 17:04 UTC (permalink / raw)
To: zsh-users
On Jan 4, 2005, at 11:55 AM, Bart Schaefer wrote:
> On Tue, 4 Jan 2005, Timothy Luoma wrote:
>
>> I'm often logged into to 3 different computers (ssh), and it would be
>> handy to be able to quickly look for the color of one to know that it
>> was the one where I was connected to X
>
> [I wrote everything that follows while thinking "connected to X" meant
> "connected using an X11 terminal emulator", but now I think it means
> "to
> the host named X" so this may all be irrelevant. Having written it
> down,
> though, I'm going to send it anyway.]
Sorry, I did indeed mean "X" as in $X not X Windows.
That said, I'm trying to learn more about X Windows, and this will be
helpful.
TjL
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-04 15:20 ` Mads Martin Joergensen
@ 2005-01-04 17:12 ` Timothy Luoma
2005-01-06 1:46 ` lists
0 siblings, 1 reply; 11+ messages in thread
From: Timothy Luoma @ 2005-01-04 17:12 UTC (permalink / raw)
To: zsh-users
On Jan 4, 2005, at 10:20 AM, Mads Martin Joergensen wrote:
>> I'm often logged into to 3 different computers (ssh), and it would be
>> handy to be able to quickly look for the color of one to know that it
>> was the one where I was connected to X
>
> I've the following .termcolors file which I source in .zshrc. It makes
> it easy to do such. Be careful to get the escape codes right.
>
> http://mmj.dk/conffiles/termcolors
Bart correctly spotted my sloppy typing when I said "X" I meant "some
computer"
I am using the Terminal program in Mac OS X, not X Windows.
TjL
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-04 15:18 can zsh set background color? Timothy Luoma
2005-01-04 15:20 ` Mads Martin Joergensen
2005-01-04 16:55 ` Bart Schaefer
@ 2005-01-05 3:50 ` Drew Perttula
2005-01-05 9:29 ` Bart Schaefer
2 siblings, 1 reply; 11+ messages in thread
From: Drew Perttula @ 2005-01-05 3:50 UTC (permalink / raw)
To: zsh-users
> Is there any way for zsh to set the background color of my terminal
> program?
>
> I'm often logged into to 3 different computers (ssh), and it would be
> handy to be able to quickly look for the color of one to know that it
> was the one where I was connected to X
>
> TjL
> Zsh 4.1.1 on Mac OS X
>
As has been discussed, you'll need a terminal program that accepts escape
codes to change the background color. But if you find that, you might be
interested in my solution, which is to hash the hostname and generate
a color from the result. I get a probably-different background color
every time I connect to a new host.
My code is on http://zshwiki.org/WishList and repeated here:
# tint the terminal for each host
bgcolor=`hostname | md5sum | /usr/local/bin/python -c "c1=raw_input(); col=[int(c1[x:x+2],16) for x in 0,2,4]; print '#%02x%02x%02x'%tuple([40*x/max(col) for x in col])"`
print "\x1b]49;$bgcolor\x07"
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-05 3:50 ` Drew Perttula
@ 2005-01-05 9:29 ` Bart Schaefer
0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2005-01-05 9:29 UTC (permalink / raw)
To: zsh-users
On Tue, 4 Jan 2005, Drew Perttula wrote:
> bgcolor=`hostname | md5sum | /usr/local/bin/python -c "c1=raw_input(); col=[int(c1[x:x+2],16) for x in 0,2,4]; print '#%02x%02x%02x'%tuple([40*x/max(col) for x in col])"`
Pipe to python? Why?
setbgcolor() {
local c1=$(hostname | md5sum) max x
local -a col
for x in 0 2 4; do col+=$[16#$c1[x+1,x+2]]; done
max=${${(On)col}[1]}
print -n "\x1b]49;#"
for x in $col; do printf %02x $[40*x/max]; done
print -n "\x07"
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-04 17:12 ` Timothy Luoma
@ 2005-01-06 1:46 ` lists
2005-01-07 23:14 ` Timothy Luoma
0 siblings, 1 reply; 11+ messages in thread
From: lists @ 2005-01-06 1:46 UTC (permalink / raw)
To: Timothy Luoma; +Cc: zsh-users
I'm personally content with a different colored prompt for remote
machines. This is taken care of in my .zshrc file with something like
this pseudo code:
case ${HOST} in
(host1) PS1=<substitute your favorite prompt here> ;;
(host2) PS1=<different colored prompt here> ;;
esac
I don't want to take the focus of this discussion off of zsh, but if
you're using OS X and Terminal, you can set up a Terminal window to
have the characteristics that you like (i.e. color of background), then
save it as a .term file which you launch only when you want to ssh to a
particular host. You can even set it so that just by launching a
particular .term file, the ssh command will be carried out for you.
Details here:
http://docs.info.apple.com/article.html?artnum=86134
http://docs.info.apple.com/article.html?artnum=152410
http://docs.info.apple.com/article.html?artnum=152408
Hope this helps.
On Jan 4, 2005, at 11:12 AM, Timothy Luoma wrote:
> I am using the Terminal program in Mac OS X, not X Windows.
>
> TjL
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-06 1:46 ` lists
@ 2005-01-07 23:14 ` Timothy Luoma
2005-01-12 7:43 ` Juhapekka Tolvanen
0 siblings, 1 reply; 11+ messages in thread
From: Timothy Luoma @ 2005-01-07 23:14 UTC (permalink / raw)
To: zsh-users
On Jan 5, 2005, at 8:46 PM, lists wrote:
> I don't want to take the focus of this discussion off of zsh, but if
> you're using OS X and Terminal, you can set up a Terminal window to
> have the characteristics that you like (i.e. color of background),
> then save it as a .term file which you launch only when you want to
> ssh to a particular host. You can even set it so that just by
> launching a particular .term file, the ssh command will be carried out
> for you. Details here:
Many thanks for that. That gets me pretty far along. One remaining
thing I want to accomplish is to set colors specifically for when I'm
logged in as root (something subtle like a BRIGHT RED BACKGROUND and a
flashing prompt saying YOU ARE ROOT!)
However, I am starting to use 'sudo' instead of logging in as root, so
that's probably a moot point now.
Thanks for the pointers on the .term files, that's a good solution for
the time being.
TjL
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-07 23:14 ` Timothy Luoma
@ 2005-01-12 7:43 ` Juhapekka Tolvanen
2005-01-12 10:18 ` David Gómez
0 siblings, 1 reply; 11+ messages in thread
From: Juhapekka Tolvanen @ 2005-01-12 7:43 UTC (permalink / raw)
To: Timothy Luoma, zsh-users
Timothy Luoma <lists@tntluoma.com> writes:
> One remaining thing I want to accomplish is to set colors specifically
> for when I'm logged in as root (something subtle like a BRIGHT RED
> BACKGROUND and a flashing prompt saying YOU ARE ROOT!)
My zsh-configs really has such prompt that distinguish root shells from
luser shells very well.
http://iki.fi/juhtolv/configs/shellrc/
--
Juhapekka "naula" Tolvanen * http colon slash slash iki dot fi slash juhtolv
"sinun kauneutesi kaataa valtakuntia. minun pimeyteni raiskaa runoutta." CMX
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: can zsh set background color?
2005-01-12 7:43 ` Juhapekka Tolvanen
@ 2005-01-12 10:18 ` David Gómez
0 siblings, 0 replies; 11+ messages in thread
From: David Gómez @ 2005-01-12 10:18 UTC (permalink / raw)
To: juhtolv; +Cc: zsh-users
Hi Juhapekka ;),
> > One remaining thing I want to accomplish is to set colors specifically
> > for when I'm logged in as root (something subtle like a BRIGHT RED
> > BACKGROUND and a flashing prompt saying YOU ARE ROOT!)
I have this on my /etc/zshenv:
if [[ $USERNAME == root ]]; then
export PS1=$'[%n@%m] %{\e[0;35m%}[%~] %{\e[0m%}%# '
else
export PS1=$'[%n@%m] %{\e[0;32m%}[%~] %{\e[0m%}%# '
fi
But it only sets the foreground color. You'll need to put another
escape sequence to change the background too.
regards,
--
David Gómez Jabber ID: davidge@jabber.org
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-01-12 10:21 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-04 15:18 can zsh set background color? Timothy Luoma
2005-01-04 15:20 ` Mads Martin Joergensen
2005-01-04 17:12 ` Timothy Luoma
2005-01-06 1:46 ` lists
2005-01-07 23:14 ` Timothy Luoma
2005-01-12 7:43 ` Juhapekka Tolvanen
2005-01-12 10:18 ` David Gómez
2005-01-04 16:55 ` Bart Schaefer
2005-01-04 17:04 ` Timothy Luoma
2005-01-05 3:50 ` Drew Perttula
2005-01-05 9:29 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).