commit 5b4f57a6ef7d460476fe08d7537f22d20c02d2ec
parent 50c638ef3886401c81e290c8ad57d332eb7e5a3b
Author: Jacob R. Edwards <n/a>
Date: Sat, 12 Feb 2022 14:06:01 -0800
Remove force flag and improve ask() in modsync
The n[opatch] flag is now used in place of the force flag to determine
whether to pull changes before the stop command is issued.
The ask function now only prints a prompt if both the 0 and 2 file
descriptors are terminals. Additionally EOF now is handled properly.
Diffstat:
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/lib/modsync b/lib/modsync
@@ -11,16 +11,15 @@ error() {
}
usererror() {
- error "usage: $name [push|pull|diff|stop] [-cdfnop] dest module ..."
+ error "usage: $name [push|pull|diff|stop] [-cdnop] dest module ..."
test "${1:-}" &&
error "$@"
}
ask() {
- # No yes-forever answer, use yes(1)
- test -t &&
+ test -t 0 -a -t 2 &&
echo -n "$1? [$2] " 1>&2
- sed '1{ s/^$/'$2'/; q; }' | grep -q '^[Yy]'
+ awk -vd="$2" '{ a=$0; exit } END{ if(!a) a=d; exit a !~ "^[Yy]" }'
}
# Could be dynamically generated for efficiency, install(1) is also
@@ -109,7 +108,6 @@ owner=
perms=
fdiff=false
fcopy=false
-force=false
while expr x"$1" : x- > /dev/null
do
case "$1" in
@@ -118,7 +116,6 @@ do
(-p) perms="$2"; shift ;;
(-d) fdiff=true ;;
(-c) fcopy=true ;;
- (-f) force=true ;;
(*) usererror "$name: '$1': Invalid option" ;;
esac
shift
@@ -129,8 +126,7 @@ shift
trap "" 0
-# Pull changes before removing
-if test "$cmd" = stop && ! $force
+if test "$cmd" = stop && $patch
then
"$0" pull "$dir" "$@"
fi