-
Notifications
You must be signed in to change notification settings - Fork 18
/
unix-shell-script-tactics-demo
executable file
·143 lines (115 loc) · 3.35 KB
/
unix-shell-script-tactics-demo
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#/bin/sh
set -euf
## Program Tracking
program_command="unix-shell-script-tactics"
program_version="7.0.0"
program_created="2022-10-23T15:55:59Z"
program_updated="2023-05-08T19:47:33Z"
program_license="GPL-2.0 or GPL-3.0 or contact us for more"
program_website="https://example.com/example/"
program_contact="Alice Adams ([email protected])"
## Source https://github.com/sixarm/unix-shell-script-kit
. "$(dirname "$(readlink -f "$0")")/unix-shell-script-kit"
## Help Function
help(){
cat << EOF
Unix shell script style guide demo
Syntax:
unix-shell-script-tactics
Example:
unix-shell-script-tactics --version
## Options
* -h --help:
print helpful information
* -v --verbose:
increase the verbose level
* -V --version:
print the program version number
* --foo=<value>:
set the foo variable to a value
## Options to print program information
* --program-command:
print the program command name
* --program-version:
print the program version number
* --program-created:
print the program created date
* --program-updated:
print the program updated date
* --program-license:
print the program license name
* --program-website:
print the program website URL
* --program-contact:
print the program contact information for the maintainer
## Tracking
* Command: $program_command
* Version: $program_version
* Created: $program_created
* Updated: $program_updated
* License: $program_license
* Website: $program_website
* Contact: $program_contact
EOF
}
temp_home() { out $(mktemp -d -t "${1:-$(zid)}"); }; export -f temp_home;
verbose=0
while :; do
case $1 in
--)
shift
break
;;
-h|--help)
help; exit 0;
;;
-v|--verbose)
verbose=$((verbose + 1))
;;
-V|--version)
out "$program_version"; exit 0;
;;
# Options that print program information variables.
# These variables are all set at the top of the script.
--program-command)
out "$program_command"; exit 0;
;;
--program-version)
out "$program_version"; exit 0;
;;
--program-created)
out "$program_created"; exit 0;
;;
--program-updated)
out "$program_updated"; exit 0;
;;
--program-license)
out "$program_license"; exit 0;
;;
--program-website)
out "$program_website"; exit 0;
;;
--program-contact)
out "$program_contact"; exit 0;
;;
# Catch-all that enables arbitrary options such as key=val.
# Depending on your goals, you can use this section or not.
--*=*)
key="${1#--}"; key="${key%%=*}";
val="${1#*=}";
eval "$key"=\$val
shift
;;
# Catch-all for unexpected input that looks like an option.
# Depending on your goals, you can use this section or not.
-?*)
die "The command line option is unknown: " "$1"
;;
# Any other arguments are to be treated as content, or as positional
# arguments that are parsed later, thus break out of this loop.
*)
break
;;
esac
shift
done