Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: can zsh set background color?

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) ]]
    command xterm "$@"
    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]}]}" ]]
    command xterm -fg $color "$@"
---- 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.)

Messages sorted by: Reverse Date, Date, Thread, Author