@@ -419,23 +419,22 @@ More info on GitHub:
419
419
https://github.com/marioortizmanero/polybar-pulseaudio-control"
420
420
}
421
421
422
- while [[ " $1 " = --* ]]; do
423
- unset arg
424
- unset val
422
+ # Obtains the value for an option and returns 1 if no shift is needed.
423
+ function getOptVal() {
425
424
if [[ " $1 " = * = * ]]; then
426
- arg=" ${1// =*/ } "
427
425
val=" ${1//* =/ } "
428
- shift
429
- else
430
- arg=" $1 "
431
- # Support space-separated values, but also value-less flags
432
- if [[ " $2 " != --* ]]; then
433
- val=" $2 "
434
- shift
435
- fi
436
- shift
426
+ return 1
437
427
fi
438
428
429
+ val=" $2 "
430
+ }
431
+
432
+ # Parsing the options from the arguments
433
+ while [[ " $1 " = --* ]]; do
434
+ unset arg
435
+ unset val
436
+
437
+ arg=" $1 "
439
438
case " $arg " in
440
439
--autosync)
441
440
AUTOSYNC=yes
@@ -444,6 +443,7 @@ while [[ "$1" = --* ]]; do
444
443
AUTOSYNC=no
445
444
;;
446
445
--color-muted|--colour-muted)
446
+ if getOptVal " $@ " ; then shift ; fi
447
447
COLOR_MUTED=" %{F#$val }"
448
448
;;
449
449
--notifications)
@@ -459,31 +459,40 @@ while [[ "$1" = --* ]]; do
459
459
OSD=no
460
460
;;
461
461
--icon-muted)
462
+ if getOptVal " $@ " ; then shift ; fi
462
463
ICON_MUTED=" $val "
463
464
;;
464
465
--icon-sink)
466
+ if getOptVal " $@ " ; then shift ; fi
465
467
# shellcheck disable=SC2034
466
468
ICON_SINK=" $val "
467
469
;;
468
470
--icons-volume)
471
+ if getOptVal " $@ " ; then shift ; fi
469
472
IFS=, read -r -a ICONS_VOLUME <<< " ${val//[[:space:]]/}"
470
473
;;
471
474
--volume-max)
475
+ if getOptVal " $@ " ; then shift ; fi
472
476
VOLUME_MAX=" $val "
473
477
;;
474
478
--volume-step)
479
+ if getOptVal " $@ " ; then shift ; fi
475
480
VOLUME_STEP=" $val "
476
481
;;
477
482
--sink-blacklist)
483
+ if getOptVal " $@ " ; then shift ; fi
478
484
IFS=, read -r -a SINK_BLACKLIST <<< " ${val//[[:space:]]/}"
479
485
;;
480
486
--sink-nicknames-from)
487
+ if getOptVal " $@ " ; then shift ; fi
481
488
SINK_NICKNAMES_PROP=" $val "
482
489
;;
483
490
--sink-nickname)
491
+ if getOptVal " $@ " ; then shift ; fi
484
492
SINK_NICKNAMES[" ${val//:*/ } " ]=" ${val//*: } "
485
493
;;
486
494
--format)
495
+ if getOptVal " $@ " ; then shift ; fi
487
496
FORMAT=" $val "
488
497
;;
489
498
# Undocumented because the `help` action already exists, but makes the
@@ -497,8 +506,10 @@ while [[ "$1" = --* ]]; do
497
506
exit 1
498
507
;;
499
508
esac
509
+ shift
500
510
done
501
511
512
+ # Parsing the action from the arguments
502
513
case " $1 " in
503
514
up)
504
515
volUp
@@ -530,6 +541,9 @@ case "$1" in
530
541
help)
531
542
usage
532
543
;;
544
+ " " )
545
+ echo " No action specified. Run \` $0 help\` for more information." >&2
546
+ ;;
533
547
* )
534
548
echo " Unrecognised action: $1 " >&2
535
549
exit 1
0 commit comments