Skip to content

Commit 8ba0b33

Browse files
Fix arguments
1 parent dabdb49 commit 8ba0b33

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

pulseaudio-control.bash

+24-11
Original file line numberDiff line numberDiff line change
@@ -427,23 +427,21 @@ More info on GitHub:
427427
https://github.com/marioortizmanero/polybar-pulseaudio-control"
428428
}
429429

430-
while [[ "$1" = --* ]]; do
431-
unset arg
432-
unset val
430+
function getArgVal() {
433431
if [[ "$1" = *=* ]]; then
434-
arg="${1//=*/}"
435432
val="${1//*=/}"
436-
shift
437433
else
438-
arg="$1"
439-
# Support space-separated values, but also value-less flags
440-
if [[ "$2" != --* ]]; then
441-
val="$2"
442-
shift
443-
fi
434+
val="$2"
444435
shift
445436
fi
437+
}
446438

439+
# Parsing the options from the arguments
440+
while [[ "$1" = --* ]]; do
441+
unset arg
442+
unset val
443+
444+
arg="$1"
447445
case "$arg" in
448446
--autosync)
449447
AUTOSYNC=yes
@@ -452,6 +450,7 @@ while [[ "$1" = --* ]]; do
452450
AUTOSYNC=no
453451
;;
454452
--color-muted|--colour-muted)
453+
getArgVal "$@"
455454
COLOR_MUTED="%{F#$val}"
456455
;;
457456
--notifications)
@@ -467,31 +466,40 @@ while [[ "$1" = --* ]]; do
467466
OSD=no
468467
;;
469468
--icon-muted)
469+
getArgVal "$@"
470470
ICON_MUTED="$val"
471471
;;
472472
--icon-sink)
473+
getArgVal "$@"
473474
# shellcheck disable=SC2034
474475
ICON_SINK="$val"
475476
;;
476477
--icons-volume)
478+
getArgVal "$@"
477479
IFS=, read -r -a ICONS_VOLUME <<< "${val//[[:space:]]/}"
478480
;;
479481
--volume-max)
482+
getArgVal "$@"
480483
VOLUME_MAX="$val"
481484
;;
482485
--volume-step)
486+
getArgVal "$@"
483487
VOLUME_STEP="$val"
484488
;;
485489
--sink-blacklist)
490+
getArgVal "$@"
486491
IFS=, read -r -a SINK_BLACKLIST <<< "${val//[[:space:]]/}"
487492
;;
488493
--sink-nicknames-from)
494+
getArgVal "$@"
489495
SINK_NICKNAMES_PROP="$val"
490496
;;
491497
--sink-nickname)
498+
getArgVal "$@"
492499
SINK_NICKNAMES["${val//:*/}"]="${val//*:}"
493500
;;
494501
--format)
502+
getArgVal "$@"
495503
FORMAT="$val"
496504
;;
497505
# Undocumented because the `help` action already exists, but makes the
@@ -505,8 +513,10 @@ while [[ "$1" = --* ]]; do
505513
exit 1
506514
;;
507515
esac
516+
shift
508517
done
509518

519+
# Parsing the action from the arguments
510520
case "$1" in
511521
up)
512522
volUp
@@ -538,6 +548,9 @@ case "$1" in
538548
help)
539549
usage
540550
;;
551+
"")
552+
echo "No action specified. Run \`$0 help\` for more information." >&2
553+
;;
541554
*)
542555
echo "Unrecognised action: $1" >&2
543556
exit 1

0 commit comments

Comments
 (0)