From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21270 invoked by alias); 12 Feb 2015 05:22:32 -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: 19861 Received: (qmail 19661 invoked from network); 12 Feb 2015 05:22:20 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=QM3fnbPO c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=0HtSIViG9nkA:10 a=FqN7YmLYFXQIWikL3L8A:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150211212216.ZM19366@torch.brasslantern.com> Date: Wed, 11 Feb 2015 21:22:16 -0800 In-reply-to: <20150211165618.GA5230@tarsus.local2> Comments: In reply to Daniel Shahaf "Re: exclude users in watch variable?" (Feb 11, 4:56pm) References: <20150204174605.GA14529@spiegl.de> <20150210192857.GA13932@spiegl.de> <20150210214551.GC1829@tarsus.local2> <20150211114654.GA22015@spiegl.de> <20150211165618.GA5230@tarsus.local2> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: exclude users in watch variable? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 11, 4:56pm, Daniel Shahaf wrote: } } autoload -Uz add-zsh-hook } old= } precmd_who() { } local new="$(who)"$'\n' # add newline to reduce spurious diffs } if [[ -n $old ]] ; then diff =(<<<$old) =(<<<$new) ; fi } old=$new } } } add-zsh-hook precmd precmd_who } } If 'who' doesn't run quickly in your environment you'll notice delays This seems like an ideal application for the delayed-update trick. typeset -gH update_prompt_fd old_who typeset -g normal_prompt='%m $ ' # watch_who expects a single argument that looks like "$(who)" and # compares it to the argument passed to the previous watch_who call watch_who() { local new="$1"$'\n' if [[ -n $old_who ]] then local who_prompt="$(diff =(<<<$old_who) =(<<<$new))" if [[ -n $who_prompt ]] then PROMPT="$who_prompt"$'\n'"$normal_prompt" fi fi old_who="$new" } # update_who is a ZLE I/O handler, which reads output from a background # process (expected to be "who"), passes it through watch_who, and then # deletes the handler instance and updates the prompt update_who () { watch_who "$(read -d '' -rE -u$1)" update_prompt_fd=0 zle -F $1 exec {1}>&- zle reset-prompt } zle -N update_who # precmd_who sets up the update_who handler if it is available, and # otherwise runs watch_who directly to put the diffs into the prompt. # If your "who" is fast, simply skip the "zle -N" above. precmd_who() { PROMPT="$normal_prompt" if zle -l update_who then (( update_prompt_fd )) && zle -F $update_prompt_fd >/dev/null exec {update_prompt_fd}<<( who ) zle -F -w $update_prompt_fd update_who else watch_who "$(who)" fi } autoload -Uz add-zsh-hook add-zsh-hook precmd precmd_who