[tz] [PATCH 5/5] tzselect.ksh: add script mode option

J William Piggott elseifthen at gmx.com
Wed Jan 20 16:50:10 UTC 2016


The last message from tzselect states:
"... use the tzselect command in shell scripts"

To do so there needs to be a way to silence the
dialog tail. This commit adds an -s option to
facilitate that.

Signed-off-by: J William Piggott <elseifthen at gmx.com>
---
 tzselect.ksh | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/tzselect.ksh b/tzselect.ksh
index 3e8d07b..41a430f 100644
--- a/tzselect.ksh
+++ b/tzselect.ksh
@@ -50,11 +50,12 @@ say() {
 	exit 1
 }
 
+script_mode=0
 coord=
 location_limit=10
 zonetabtype=zone1970
 
-usage="Usage: tzselect [--version] [--help] [-c COORD] [-n LIMIT]
+usage="Usage: tzselect [--version] [--help] [-c COORD] [-n LIMIT] [-s]
 Select a time zone interactively.
 
 Options:
@@ -70,7 +71,11 @@ Options:
   -n LIMIT
     Display at most LIMIT locations when -c is used (default $location_limit).
 
-  --version
+  -s
+    Silence the dialog, after the confirmation prompt is answered, to
+    facilitate calling tzselect from other applications.
+
+ --version
     Output version information.
 
   --help
@@ -146,13 +151,15 @@ else
   }
 fi
 
-while getopts c:n:t:-: opt
+while getopts sc:n:t:-: opt
 do
     case $opt$OPTARG in
     c*)
 	coord=$OPTARG ;;
     n*)
 	location_limit=$OPTARG ;;
+    s )
+	script_mode=1 ;;
     t*) # Undocumented option, used for developer testing.
 	zonetabtype=$OPTARG ;;
     -help)
@@ -544,17 +551,19 @@ Raw System Clock time:	$UTdate."
 do coord=
 done
 
-case $SHELL in
-*csh) file=.login line="setenv TZ '$TZ'";;
-*) file=.profile line="TZ='$TZ'; export TZ"
-esac
+if test $script_mode -ne 1 ; then
+  case $SHELL in
+  *csh) file=.login line="setenv TZ '$TZ'";;
+  *) file=.profile line="TZ='$TZ'; export TZ"
+  esac
 
-say >&2 "
+  say >&2 "
 You can make this change permanent for yourself by appending the line
 	$line
 to the file '$file' in your home directory; then log out and log in again.
 
 Here is that TZ value again, this time on standard output so that you
 can use the $0 command in shell scripts:"
+fi
 
 say "$TZ"


More information about the tz mailing list