summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2021-11-09 16:30:53 -0500
committerSteven <steven.vasilogianis@gmail.com>2021-11-09 16:30:53 -0500
commit2eefd096122d569e244fd84dee9a02920fd87499 (patch)
tree0560df9d9620e6cb0328f43125e6660ec0ec16c7
parentc72e2a9e105aeed24dd407ac8aa61203e3baf7c6 (diff)
Generate skeleton shell scripts
-rwxr-xr-xshopenscad.sh19
1 files changed, 17 insertions, 2 deletions
diff --git a/shopenscad.sh b/shopenscad.sh
index e8b350f..6d85de6 100755
--- a/shopenscad.sh
+++ b/shopenscad.sh
@@ -8,6 +8,7 @@ INTERACTIVE=
8PRINT_VARS= 8PRINT_VARS=
9USER_OUTPUT_FILENAME= 9USER_OUTPUT_FILENAME=
10SCAD_FILE= 10SCAD_FILE=
11SHELL_SKEL=
11 12
12help() 13help()
13{ 14{
@@ -22,6 +23,7 @@ Usage: $0 [-h] [-n] [-p] [-i] [-o OUTPUT-FILENAME] INPUT.scad
22 -p, --print-vars print variables parsed from INPUT.scad 23 -p, --print-vars print variables parsed from INPUT.scad
23 -i, --interactive show output command and query for execution 24 -i, --interactive show output command and query for execution
24 -n, --no-act show output command, do not execute 25 -n, --no-act show output command, do not execute
26 -s, --shell-skel initialize a skeleton shell script
25 -o, --output-filename Specify an output filename. The following variables are 27 -o, --output-filename Specify an output filename. The following variables are
26 available to you: 28 available to you:
27 29
@@ -62,8 +64,8 @@ EOF
62parse_options() 64parse_options()
63{ 65{
64 OPTS=$(getopt \ 66 OPTS=$(getopt \
65 --options 'hpino:' \ 67 --options 'hpinso:' \
66 --longoptions 'help,print-vars,interactive,no-act,output-filename:' \ 68 --longoptions 'help,print-vars,interactive,no-act,shell-skel,output-filename:' \
67 -- "$@") 69 -- "$@")
68 eval set -- "$OPTS" 70 eval set -- "$OPTS"
69 unset OPTS 71 unset OPTS
@@ -79,6 +81,7 @@ parse_options()
79 -p | --print-vars ) PRINT_VARS=y;; 81 -p | --print-vars ) PRINT_VARS=y;;
80 -i | --interactive ) INTERACTIVE=y;; 82 -i | --interactive ) INTERACTIVE=y;;
81 -n | --no-act ) RUN=;; 83 -n | --no-act ) RUN=;;
84 -s | --shell-skel ) SHELL_SKEL=y;;
82 -o | --output-filename ) shift; USER_OUTPUT_FILENAME=$1;; 85 -o | --output-filename ) shift; USER_OUTPUT_FILENAME=$1;;
83 -- ) shift; break;; 86 -- ) shift; break;;
84 esac 87 esac
@@ -189,6 +192,18 @@ main()
189 exit 192 exit
190 fi 193 fi
191 194
195 if [ "$SHELL_SKEL" ]; then
196 all_vars=$($0 $SCAD_FILE -p |sed -e 's/^/# /')
197 cat <<EOF
198#!/bin/bash
199shopenscad_cmd="$0 $SCAD_FILE "
200export \$(echo \$(\$shopenscad_cmd -p))
201${all_vars}
202\$shopenscad_cmd
203EOF
204 exit;
205 fi;
206
192 ALL=$(strip_trailing "$var_sep" "$ALL") 207 ALL=$(strip_trailing "$var_sep" "$ALL")
193 VALUES=$(strip_trailing "$val_sep" "$VALUES") 208 VALUES=$(strip_trailing "$val_sep" "$VALUES")
194 209