-
Notifications
You must be signed in to change notification settings - Fork 2
/
mkls
executable file
·29 lines (27 loc) · 1.01 KB
/
mkls
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
#!/usr/bin/env bash
set -euo pipefail
#
# generate a list and diff against self
# useful inside Makefile where script creates a bunch of files
# and we only need to run the next step if there are new file names
# for example, this Makefile only runs step2 if we haven't run `make` today
# init.log:
# touch txt/$`date +%F`
# mkls init.log 'txt/*'
# step2.log: init.log
# echo hi > txt/`date +%F`
# mkls step2.log
# LOG:
# 20190718 - init
# 20191024 - outsource to mkifdiff
[[ $# -lt 1 ]] && echo "USAGE: $0 dirlist.txt '/list/*/files'\n find -iname '*thing*' | $0 dirlist.txt" && exit 1
! command -v mkifdiff >/dev/null && echo "missing mkifdiff; cannot run $0!" && exit 1
CMPFILE="$1"; shift
# write list to TMPFILE - either have a pattern to ls or piping from e.g. find
if [ $# -ge 1 ]; then
ls -d "$@" | mkifdiff "$CMPFILE"
else
echo "DEPRECATED: use mkifdiff for pipe compare" >&2
tty >/dev/null && echo "need to pipe to $0; cmd | $0 $1" && exit 1
cat | mkifdiff "$CMPFILE"
fi