From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24020 invoked by alias); 14 Feb 2014 05:25:12 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18444 Received: (qmail 14441 invoked from network); 14 Feb 2014 05:25:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 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; Date: Thu, 13 Feb 2014 21:07:40 -0800 From: Phil Pennock To: zsh-users@zsh.org Subject: neat prompt hack: mark non-exported var Message-ID: <20140214050740.GA58270@redoubt.spodhuis.org> Mail-Followup-To: zsh-users@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: 8bit 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-----