zsh-workers
 help / color / mirror / code / Atom feed
From: Han Boetes <hboetes@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: zsh-workers@zsh.org
Subject: Re: zsh watch function
Date: Sun, 17 May 2020 01:10:26 +0200	[thread overview]
Message-ID: <CAOzo9e7tnn=HYYUEBoij3Sd1RPPXrxXA2Rb8o8g4jm6YMcZ8cA@mail.gmail.com> (raw)
In-Reply-To: <20200516205926.45d04fc5@tarpaulin.shahaf.local2>

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

Hello Daniel,

That's very observant indeed. Here is a new version. I also choose printf
'\033c' in favour of the external command "clear."

Please tell if I missed anything else.

watch () {
    local PAD
    local IN=2
    case $1 in
        -n)
            IN=$2
            shift 2
            ;;
    esac
    printf '\033c'
    local CM="$*"
    local LEFT="$(printf 'Every %.1f: %s' $IN $CM)"
    ((PAD = COLUMNS - ${#LEFT}))
    while :
    do
        echo -nE "$LEFT"
        printf "%${PAD}s\n" "$HOST $(date)"
        eval "$CM"
        sleep $IN
        printf '\033c'
    done
}

On Sat, May 16, 2020 at 10:59 PM Daniel Shahaf <d.s@daniel.shahaf.name>
wrote:

> Han Boetes wrote on Sat, 16 May 2020 16:31 +0200:
> > And then I saw the padding light, here an improved version:
> >
> > watch () {
> >     IN=2
>
> The code isn't WARN_CREATE_GLOBAL-clean.
>
> >     CM="$*"
> >     LEFT="$(printf 'Every %.1f: %s' $IN $CM)"
> ⋮
> >         printf "$LEFT%${PAD}s\n" "$HN $(date)"
>
> $LEFT may contain unescaped percent signs from the input.
>
> >         eval "$CM"
> >         sleep $IN
> >         clear
> >     done
> > }
>
> For context to others, note that watch(1) on FreeBSD does something
> entirely different to what watch(1) does on Linux.
>

  reply	other threads:[~2020-05-16 23:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-16 12:20 Han Boetes
2020-05-16 14:31 ` Han Boetes
2020-05-16 20:59   ` Daniel Shahaf
2020-05-16 23:10     ` Han Boetes [this message]
2020-05-16 14:36 ` Roman Perepelitsa

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='CAOzo9e7tnn=HYYUEBoij3Sd1RPPXrxXA2Rb8o8g4jm6YMcZ8cA@mail.gmail.com' \
    --to=hboetes@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-workers@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).