alpha
Login
or
Join now
j3s.sh
/
dotfiles
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
my dotz
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
add witness for watching
author
Jes Olson
date
3 years ago
(Feb 28, 2023, 11:18 AM -0800)
commit
c55c7e8a
c55c7e8ad4225f94aa4c155848231d03a661785c
parent
5f09e7da
5f09e7daf0b61e015eae5e0f402d75bbdf76adf9
+23
1 changed file
Expand all
Collapse all
Unified
Split
bin
witness
+23
bin/witness
Reviewed
···
1
1
+
#!/bin/sh
2
2
+
#
3
3
+
# witness - watch a file for changes & run a command
4
4
+
5
5
+
file="$1"
6
6
+
shift
7
7
+
command="$@"
8
8
+
9
9
+
get_access_time() {
10
10
+
stat -c %Z "$1"
11
11
+
}
12
12
+
13
13
+
ltime="$(get_access_time "$file")"
14
14
+
15
15
+
while true; do
16
16
+
atime="$(get_access_time "$file")"
17
17
+
if [ "$atime" != "$ltime" ]; then
18
18
+
printf "witness: '%s' changed, running '%s'\n" "$file" "$command"
19
19
+
$command
20
20
+
ltime="$atime"
21
21
+
fi
22
22
+
sleep 0.5
23
23
+
done