* Misterous bug with %(# ...
@ 2005-02-06 21:13 beber mailing
2005-02-07 5:04 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: beber mailing @ 2005-02-06 21:13 UTC (permalink / raw)
To: zsh-users
Hello :) (first scuse for my poor english)
Reading the zsh's man, I see a function that interest me a lot :
%(x.true text.false text)
I'm using it for jobs, and for $?. It's working very good.
I wanted to change the prompt color if I'm logged as root. So I put
this in my zshrc :
host_color=%(#.magenta.green)
And after I'm using the host_color for coloration (You can see the
full zshrc at the end of mail) :
host="%{$fg[$host_color]%}(%m)"
warninfo="%{$fg[$host_color]%}^^ ROOT ^^ "
But the color for $host is always black, I don't know why.
When I do a echo $host, I have this :
%(#.magenta.cyan)
It seem to be good.
Maybe somebody already have this error ?
Thanks
Beber
The full zshrc :
# /etc/zsh/zprofile
# $Header: /var/cvsroot/gentoo-x86/app-shells/zsh/files/zprofile,v 1.1
2003/07/23 17:48:19 usata Exp $
[[ -e "/etc/profile.env" ]] && source /etc/profile.env
#077 would be more secure, but 022 is generally quite realistic
umask 022
if [[ "$USER" == root ]]; then
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}:/${HOME}/bin:/usr/share/bin"
else
export PATH="/bin:/usr/bin:${PATH}:/${HOME}/bin:/usr/share/bin"
fi
unset ROOTPATH
# Alias
alias l="ls --color=auto"
alias ls="ls --color=auto"
alias la="ls --color=auto -a"
alias lh="ls --color=auto -lh"
alias ll="ls --color=auto -l"
alias lha="ls --color=auto -lha"
# List only file beginning with "."
alias lsa="ls -ld .*"
# List only directories and symbolic
# links that point to directories
alias lsd="ls -ld *(-/DN)"
alias \.="pwd"
alias \.\.="cd .."
alias mp="mplayer"
alias j="jobs"
alias v="vim"
# Global aliases -- These do not have to be
# at the beginning of the command line.
alias -g M='| more'
alias -g H='| head'
alias -g T='| tail'
alias -g L='| less'
alias -g C='| cat'
# Alias selon compte
case $USER in
root)
alias distccmon="DISTCC_DIR=/var/tmp/portage/.distcc
distccmon-gnome"
;;
beber)
alias modprobe="sudo /sbin/modprobe"
alias rmmod="sudo /sbin/rmmod"
alias halt="sudo /sbin/halt"
alias reboot="sudo /sbin/reboot"
;;
*)
alias mv="mv -i"
;;
esac
# Completion emerge
autoload -U compinit promptinit
compinit
promptinit;
# Colorisation du shell
autoload -U colors
colors
host_color=%(#.magenta.green)
echo $host_color
path_color="cyan"
date_color="blue"
date_format="%d/%m %T"
date="%{$fg[$date_color]%}%D{$date_format}"
jobs="%1(j.%j .)"
ret="%0(?..:( )"
case $USER in
root)
#host_color="magenta"
host="%{$fg[$host_color]%}(%m)"
warninfo="%{$fg[$host_color]%}^^ ROOT ^^ "
;;
*)
host="%{$fg[$host_color]%}(%n@%m)"
;;
esac
cpath="%{$fg[$path_color]%}%~"
end="%{$reset_color%}"
PS1="$jobs$warninfo$cpath$end $ret%# "
RPS1="$host $date$end"
# Aide
#unalias run-help
#autoload run-help
# Cache de completion
zstyle ':completion::complete:*' use-cache 1
#zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
# history settings
HISTFILE=~/.zshhistory
HISTSIZE=3000
SAVEHIST=3000
# Bindkeys
bindkey "^A" beginning-of-line
bindkey "^E" end-of-line
bindkey "^X" delete-char
bindkey "^W" delete-word
bindkey -v # vi key bindings
bindkey "^V" vi-cmd-mode
# Exports
export VISUAL=/usr/bin/vim
export EDITOR=/usr/bin/vim
# Mail
export MAIL=~/Maildir
export MAILCHECK=60
# Afficher les nouvelles connections
case $USER in
root|beber)
watch=( $(< /etc/passwd | cut -d ':' -f 1) )
#watch=(notme) # watch for everybody but me
LOGCHECK=60 # check every 1 min
for login/logout activity
WATCHFMT='%n %a %l from %M at %T.'
;;
esac
# Options de correction
setopt correct correctall #mailwarning
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Misterous bug with %(# ...
2005-02-06 21:13 Misterous bug with %(# beber mailing
@ 2005-02-07 5:04 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2005-02-07 5:04 UTC (permalink / raw)
To: beber mailing, zsh-users
On Feb 6, 10:13pm, beber mailing wrote:
}
} host_color=%(#.magenta.green)
} host="%{$fg[$host_color]%}(%m)"
} warninfo="%{$fg[$host_color]%}^^ ROOT ^^ "
[...]
} PS1="$jobs$warninfo$cpath$end $ret%# "
} RPS1="$host $date$end"
}
} But the color for $host is always black, I don't know why.
You have a problem with understanding the order of evaluation.
%(#.true.false) is evaluated only when a prompt is printed, not at
other times when variables are interpolated. What's happening is that
the value of $fg[%(#.magenta.green)] is looked up at the time of the
assignment to "host" -- and there is no key "%(#.magenta.green)" in the
$fg associative array, so that returns nothing. By the time the various
remaining %-expandos in the PS1 and RPS1 strings are interpreted, it's
too late.
What you need is:
host_color="%(#.$fg[magenta].$fg[green])"
host="%{$host_color%}(%m)"
warninfo="%{$host_color%}^^ ROOT ^^ "
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-02-07 6:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-06 21:13 Misterous bug with %(# beber mailing
2005-02-07 5:04 ` 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).