zsh-users
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-users@zsh.org
Subject: neat prompt hack: mark non-exported var
Date: Thu, 13 Feb 2014 21:07:40 -0800	[thread overview]
Message-ID: <20140214050740.GA58270@redoubt.spodhuis.org> (raw)

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


             reply	other threads:[~2014-02-14  5:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14  5:07 Phil Pennock [this message]
2014-02-14  5:55 ` Phil Pennock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140214050740.GA58270@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).