zsh-workers
 help / color / mirror / code / Atom feed
* zsh watch function
@ 2020-05-16 12:20 Han Boetes
  2020-05-16 14:31 ` Han Boetes
  2020-05-16 14:36 ` Roman Perepelitsa
  0 siblings, 2 replies; 5+ messages in thread
From: Han Boetes @ 2020-05-16 12:20 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 868 bytes --]

In this online question someone asked if a watch internal command was
available, like with bash:

https://unix.stackexchange.com/questions/260323/watch-equivalent-in-zsh

I couldn't help myself but to write the code for that. Fun fact is that
code-colouring and aliases work. This code is probably not fool proof. Feel
free to improve. Please consider adding it in improved form to the ZSH
distribution.

watch () {
    IN=2
    case $1 in
        -n)
            IN=$2
            shift 2
            ;;
    esac
    clear
    HN="$(hostname)"
    HD="$(printf 'Every %.1f: ' $IN)"
    CM="$*"
    # Where does that -2 come from?
    ((PAD = COLUMNS - ${#HD} - ${#CM} - ${#DT} - 2))
    while :
    do
        DT=$(date)
        printf "$HD%s%${PAD}s: %s\n\n" "$CM" "$HN" "$DT"
        # echo "$LFT $RHT"
        eval "$CM"
        sleep $IN
        clear
    done
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-16 23:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-16 12:20 zsh watch function Han Boetes
2020-05-16 14:31 ` Han Boetes
2020-05-16 20:59   ` Daniel Shahaf
2020-05-16 23:10     ` Han Boetes
2020-05-16 14:36 ` Roman Perepelitsa

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