-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch
More file actions
executable file
·69 lines (58 loc) · 2.28 KB
/
watch
File metadata and controls
executable file
·69 lines (58 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
#
# ############################################################################
# Project: scripts (none)
# File...: watch
# Created: Saturday, 2024/12/14 - 13:04:40
# Author.: fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Saturday, 2024/12/14 - 23:24:35
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 0.0.1.83
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
# shellcheck disable=SC1090,SC2154
# * SC1090: Can't follow non-constant source. Use a directive to specify location.
# -> cant follow or source usage
# * SC2154: var is referenced but not assigned.
# -> variables created by or library system (don't worry)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
source "$xSHELL_INIT"
use args
xrequirements clear sleep tput xhr diff
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
# define your arguments with 'xarg' function. Example below:
xarg --id -c,--command --var cmd+r --desc "command to watch"
xarg --id -s,--seconds --var secs+r --desc "seconds to run again"
xhelp --header="wrapper for 'watch' command or a function on Darwin systems"
xrun --xreject-unknow --xrequire-one --xcolors --xversionrc "$@"
# define seconds to wait and run cmd again
[ -z "$secs" ] && seconds=2 || seconds=$secs
if builtin watch; then
watch "$@"
else
output1=/tmp/watch-output1
output2=/tmp/watch-output2
# clear previous outputs
rm $output1 $output2
while :; do
clear
echo "watch: '$cmd' - reload: '$seconds' secs"
xhr -c "-"
# eval "$cmd"
[ -f "$output1" ] && cat $output1 > $output2
bash -c "$cmd" > $output1
if [ ! -f "$output2" ]; then
cat $output1
else
diff -y $output1 $output2
fi
sleep "$seconds"
done
fi