From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: exclude users in watch variable?
Date: Wed, 11 Feb 2015 21:22:16 -0800 [thread overview]
Message-ID: <150211212216.ZM19366@torch.brasslantern.com> (raw)
In-Reply-To: <20150211165618.GA5230@tarsus.local2>
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
next prev parent reply other threads:[~2015-02-12 5:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-04 17:46 Andy Spiegl
2015-02-10 19:28 ` Andy Spiegl
2015-02-10 21:45 ` Daniel Shahaf
2015-02-11 11:46 ` Andy Spiegl
2015-02-11 16:56 ` Daniel Shahaf
2015-02-12 5:22 ` Bart Schaefer [this message]
2015-02-11 12:26 ` Peter Stephenson
2015-02-11 15:16 ` Andy Spiegl
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=150211212216.ZM19366@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--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).