zsh-users
 help / color / mirror / code / Atom feed
* neat prompt hack: mark non-exported var
@ 2014-02-14  5:07 Phil Pennock
  2014-02-14  5:55 ` Phil Pennock
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Pennock @ 2014-02-14  5:07 UTC (permalink / raw)
  To: zsh-users

-----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-----


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: neat prompt hack: mark non-exported var
  2014-02-14  5:07 neat prompt hack: mark non-exported var Phil Pennock
@ 2014-02-14  5:55 ` Phil Pennock
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Pennock @ 2014-02-14  5:55 UTC (permalink / raw)
  To: zsh-users

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 2014-02-13 at 21:07 -0800, Phil Pennock wrote:
> : ${ZSH_THEME_CONTINUUM_APCNOTEXPORTED:='⚠⚠⚠'}

Mutt showed that line to me as ending:  :=''
(no closing brace, empty value).

If you see that, pipe to a real text-viewer.  The line _is_ well formed,
the variable is being given a default value of one character repeated
three times, that character being 0x26A0, "WARNING SIGN".

Dangers of Unicode, even today.  *sigh*

- -Phil
-----BEGIN PGP SIGNATURE-----

iQEcBAEBCAAGBQJS/a+1AAoJEKBsj+IM0duFotAIAKTNNZIxf9qZkn5cVPfX30E5
Mnz0cEB56KVZBrKGifuYHVUcvtj4oKpOmQ5mYwDRyfVzKRz36117Bge0MIMHNNS0
4lffi6NTn6cIY/KZyFIJ44rdu09LSF0FJZxqu8tZfbieOq25A7AVtfLAe75Ojs+M
LMZurf4AW+g+fr+yT8xxfavGu1f0jz1Fb9NAz8Me88HiapYRGLd2qpIE14vTYLsG
Me9qnpXC0GKamxCNO3p5S13AW/ij46xOFPda9UmplEOYzDInF5nZcLI5OJSqA0hX
GpV+7zvpcueLU39aVjSKK3U1OJaY4i6/Mk9Cp1GavUQMj6HgytFBgtJNZKufOOs=
=afDF
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-02-14  5:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14  5:07 neat prompt hack: mark non-exported var Phil Pennock
2014-02-14  5:55 ` Phil Pennock

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).