Commit 0c5dbbebf06a8ca66772895e051800de0a61ebcc

Authored by Georg Hopp
1 parent 2c7ac2f3

Allow the password to start with a -.

In that case the options have to be terminated with a --.
In future this options should be added to all functions.
Showing 1 changed file with 11 additions and 3 deletions
... ... @@ -141,9 +141,10 @@ function amngrid() {
141 141
142 142 function amngrcrypt() {
143 143 local OPT OPTARG OPTIND PLAIN RECIPIENT
  144 + local OPTEND=0
144 145 local USAGE="$(printf "Usage: %s [-h] [-r recipient] password" "$0")"
145 146
146   - while getopts hr: OPT
  147 + while getopts hr:- OPT
147 148 do
148 149 case $OPT in
149 150 r)
... ... @@ -151,10 +152,13 @@ function amngrcrypt() {
151 152 h)
152 153 echo "${USAGE}"
153 154 return 0;;
  155 + -)
  156 + OPTEND=1;;
154 157 ?)
155 158 echo "${USAGE}"
156 159 return 1;;
157 160 esac
  161 + test ${OPTEND} -eq 1 && break
158 162 done
159 163 shift $(($OPTIND-1))
160 164
... ... @@ -201,13 +205,14 @@ function amngrgen() {
201 205
202 206 function amngradd() {
203 207 local OPT OPTARG OPTIND DESCRIPTION RECIPIENT DB
  208 + local OPTEND=0
204 209 local USAGE="$(cat <<-EOT
205 210 Usage: $0 [-h] [-d description] [-D dbfile] [-r recipient]
206 211 account [username [password]]
207 212 EOT
208 213 )"
209 214
210   - while getopts d:D:hr: OPT
  215 + while getopts d:D:hr:- OPT
211 216 do
212 217 case $OPT in
213 218 d)
... ... @@ -219,10 +224,13 @@ function amngradd() {
219 224 h)
220 225 echo "${USAGE}"
221 226 return 0;;
  227 + -)
  228 + OPTEND=1;;
222 229 ?)
223 230 echo "${USAGE}"
224 231 return 1;;
225 232 esac
  233 + test ${OPTEND} -eq 1 && break
226 234 done
227 235 shift $(($OPTIND-1))
228 236
... ... @@ -255,7 +263,7 @@ function amngradd() {
255 263
256 264 if [ "${3}" ]
257 265 then
258   - PASSWORD="$(amngrcrypt -r "${RECIPIENT}" "${3}")"
  266 + PASSWORD="$(amngrcrypt -r "${RECIPIENT}" -- "${3}")"
259 267 else
260 268 PASSWORD="$(amngrgen -r "${RECIPIENT}")"
261 269 echo -n "${PASSWORD}" | gpg -dq | xclip -i
... ...
Please register or login to post a comment