diff options
author | EuAndreh <eu@euandre.org> | 2023-05-03 17:07:12 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-05-03 17:07:12 -0300 |
commit | 0921c9d28c7abfb64c0225ce29831939bd3966d0 (patch) | |
tree | 3a94ea69185b140c1742f9de7cb98a4b530dc2fc /bin | |
parent | bin/mnt: Fix list of ACTIONs in help string (diff) | |
download | dotfiles-0921c9d28c7abfb64c0225ce29831939bd3966d0.tar.gz dotfiles-0921c9d28c7abfb64c0225ce29831939bd3966d0.tar.xz |
bin/ifnew: Add -v flag
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/ifnew | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -4,7 +4,7 @@ set -eu usage() { cat <<-'EOF' Usage: - ifnew FILE + ifnew [-v] FILE ifnew -h EOF } @@ -14,13 +14,15 @@ help() { Options: + -v notify when new -h, --help show this message FILE the target to compared against Compare STDIN to FILE, and only write to FILE if STDIN content - differs from FILE content. + differs from FILE content. When -v is given, notify on STDERR + that FILE has new content (useful for debugging purposes). Examples: @@ -41,10 +43,11 @@ help() { # timestamp 2 - Only change file when content changes in a Makefile: + Only change file when content changes in a Makefile, and print + to STDERR when it does: i18.cfg: ALWAYS - gen-cfg | ifnew $@ + gen-cfg | ifnew -v $@ po4a $@ EOF } @@ -65,8 +68,12 @@ for flag in "$@"; do esac done -while getopts 'h' flag; do +VERBOSE=false +while getopts 'vh' flag; do case "$flag" in + v) + VERBOSE=true + ;; h) usage help @@ -89,5 +96,12 @@ trap 'rm -f "$STDIN"' EXIT cat - > "$STDIN" if ! cmp -s "$STDIN" "$FILE"; then + if [ "$VERBOSE" = true ]; then + printf 'ifnew: "%s" will be updated.\n' "$FILE" >&2 + fi mv "$STDIN" "$FILE" +else + if [ "$VERBOSE" = true ]; then + printf 'ifnew: "%s" left unchanged.\n' "$FILE" >&2 + fi fi |