Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: exclude users in watch variable?

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 ]]
      local who_prompt="$(diff =(<<<$old_who) =(<<<$new))"
      if [[ -n $who_prompt ]]
      then PROMPT="$who_prompt"$'\n'"$normal_prompt"

  # 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)"
    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() {
    if zle -l update_who
      (( update_prompt_fd )) && zle -F $update_prompt_fd >/dev/null
      exec {update_prompt_fd}<<( who )
      zle -F -w $update_prompt_fd update_who
      watch_who "$(who)"

  autoload -Uz add-zsh-hook
  add-zsh-hook precmd precmd_who

Messages sorted by: Reverse Date, Date, Thread, Author