In bash
, watch
(e.g. watch -n 5 ls -l
) could be used to repeat the command at fixed intervals.
This command seem to be missing on zsh. Is there an equivalent?
watch
is not an internal command:
$ type watch
/usr/bin/watch
so make sure it installed on the system where you are running zsh
.
brew install watch
. http://stackoverflow.com/a/23370705/1175956
– snowbound
Feb 06 '16 at 11:45
I just improvised watch with: clear; while ls -lah; do sleep 2; clear; done
Interesting idea. I could write a function around that... Right, put this in your .zshrc
watch () {
IN=2
case $1 in
-n)
IN=$2
shift 2
;;
esac
printf '\033c' # clear
CM="$*"
LEFT="$(printf 'Every %.1f: %s' $IN $CM)"
((PAD = COLUMNS - ${#LEFT}))
while :
do
DT=$(date)
printf "$LEFT%${PAD}s\n" "$HOST $(date)"
eval "$CM"
sleep $IN
printf '\033c'
done
}
-d
, -g
, etc?
– GMaster
May 16 '20 at 15:45
watch
is not a builtin. It is an external command. – muru Feb 06 '16 at 10:46