Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
neat prompt hack: mark non-exported var
- X-seq: zsh-users 18444
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: neat prompt hack: mark non-exported var
- Date: Thu, 13 Feb 2014 21:07:40 -0800
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201312; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Subject:To:From:Date; bh=nv0HFjZtApRBpEbKJyq8ctrtgLTnPLS/AVIJemsBECc=; b=OWcgP0fqC9DCAsC7smQIVCNeYnCk0PMr89629Qx29lPtOHA6llIs7oSvgCJvLeBgl7rFBJjDtmLRByoxMnwvLKviAx2e0Zqw6wuVHgccEXNYXFE2GSoMF9bZ1rpYh8x4bTX/UeAarv2AkiVfBYcvKsJPReZ0J6Vjg+8QeK1Yb5HmQ9Z2jv26wnAo2xPC1XBPGbwV3GFBTou0MJOX;
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Openpgp: url=https://www.security.spodhuis.org/PGP/keys/0x3903637F.asc
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
For some colleagues who use oh-my-zsh, I just constructed a prompt theme
which references a variable which needs to be exported into the
environment. There's a neat part which (IMO) makes it worth sharing
outside of oh-my-zsh.
This is based on the existing 'cloud' theme; the key is that if
$APC_HOME is set, it overrides $HOME for looking up some tool data, and
staff here touch multiple clouds so actually use this feature. (Our
customers would not). So the idea is to show the cloud, and _which_
cloud, assuming that the last part of $APC_HOME is the cloud name.
The particularly neat part is the addition of warning signs if APC_HOME
is set but not exported; since the whole point of the var is to
influence a binary command outside the shell, this is almost certainly a
mistake. I was thinking in terms of using a ternary operator and
something from zsh/parameters, before realising zsh/parameters doesn't
have a table for exported vars. Realising that it could _all_ be done
with :+ substitutions based on ${(t)APC_HOME} marking 'scalar' vs
'scalar-export' made it easy (albeit slightly intricate in quoting
because the '}' in '%}' was claimed by the '${' if not protected).
Perhaps this mechanism to warn of non-exported control variables in the
prompt will be useful to others?
Regards,
- -Phil
- ---------------------8< apcera-cloud.zsh-theme >8-----------------------
: ${ZSH_THEME_CLOUD_PREFIX:='☁'}
# not :=, allow it to be empty:
: ${ZSH_THEME_CONTINUUM_SEPARATOR='→'}
: ${ZSH_THEME_CONTINUUM_APCNOTEXPORTED:='⚠⚠⚠'}
: ${ZSH_THEME_CONTINUUM_COLOR:=magenta}
if [[ -z $ZSH_THEME_CONTINUUM_PREFIX ]]; then
ZSH_THEME_CONTINUUM_PREFIX='${APC_HOME:+"${ZSH_THEME_CONTINUUM_SEPARATOR}%{$fg_bold[${ZSH_THEME_CONTINUUM_COLOR}]%}"}'
ZSH_THEME_CONTINUUM_PREFIX+='${(U)${APC_HOME:t}[1]}${(L)${APC_HOME:t}[2,-1]}'
ZSH_THEME_CONTINUUM_PREFIX+='${APC_HOME:+"%{$reset_color%}"}'
# This ensures that we put in a big warning if APC_HOME is not exported to environ:
ZSH_THEME_CONTINUUM_PREFIX+='${APC_HOME:+"${${${(t)APC_HOME}#scalar-export}:+"%{$fg_bold[red]%}${ZSH_THEME_CONTINUUM_APCNOTEXPORTED}%{$reset_color%}"}"}'
fi
PROMPT='%{$fg_bold[cyan]%}${ZSH_THEME_CLOUD_PREFIX}%{${reset_color}$fg[cyan]%}'"${ZSH_THEME_CONTINUUM_PREFIX}"
PROMPT+=' %{$fg_bold[green]%}%p %{$fg[green]%}%c %{$fg_bold[cyan]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$fg[cyan]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}] %{$fg[yellow]%}⚡%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}]"
- ----------------------------8< cut here >8------------------------------
(Derived from cloud.zsh-theme, part of oh-my-zsh, which is
MIT-licensed).
-----BEGIN PGP SIGNATURE-----
iQEcBAEBCAAGBQJS/aSSAAoJEKBsj+IM0duFeqUH/2a+/uQzhlXoJ/HyuHS0qP0p
w4fZuaKe2F6JZGUB+IH6FWaF91SFNHuN7w2jGtGxAl/Tw5v6bFYMgWbL3bfBltRH
1LOtbUYU3hnN2phhJdWLQGpl5BoCp9n6u7pd6uHqn9l02v5CPdGz3LZghUJBiCXH
r/Pt/d/2K/6jMLaXSzH8f99VSnchqdLUf5oFX3MYqCeYY60WbSWWp6Kxo5Zv47iC
uPSnxcyRM8q0c4eJ7JgHv/H9yEKv5a0IfPYjnrn7S7baYjMaFO1RAMP1eCeD530P
TtPqbmv6Yp+UCfxbnEnw4uMm7irfwtpy+Ar1/I9xRwWIiG8Z1NOEGQIuiBeh4T8=
=Bpy9
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author