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