diff --git a/.gitignore b/.gitignore index 38db181..d57cb1d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ debian/debhelper-build-stamp debian/files debian/pulseaudio-tcp.substvars debian/pulseaudio-tcp -*.sw* diff --git a/pulseaudio-tcp b/pulseaudio-tcp index de5cce3..fbf82a4 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -22,24 +22,16 @@ usage() { cat >&2 < ~/.config/pulse/cookie ; then - debug "Using PulseAudio cookie value as passed on the command line ..." - return 0 - else - error "Decoding Base64 value of option --cookie failed." - return 1 - fi - elif _scp "$remote_user"@"$remote_ip":.config/pulse/cookie ~/.config/pulse/cookie ; then + if _scp "$remote_user"@"$remote_ip":.config/pulse/cookie ~/.config/pulse/cookie ; then debug "Synced PulseAudio cookie from remote host $remote_ip." return 0 else @@ -475,15 +450,10 @@ do_stop() { ## # Arguments -operations=() -cookie= +operation= no_more_options=false -# shellcheck disable=SC2034 - -while [[ $# -gt 0 ]] ; do - arg=$1 - shift +for arg in "$@" ; do case "$arg" in --) no_more_options=true @@ -491,11 +461,6 @@ while [[ $# -gt 0 ]] ; do --*) "$no_more_options" && { gui=false error "Option arguments may not preceed non-option arguments." ; exit 1 ; } ;;& - --cookie) - [[ $# -eq 0 ]] && { gui=false error "Missing argument for option \"--cookie\"" ; exit 1 ; } - cookie=$1 - shift - ;; --debug) debug_cmdline=true ;; @@ -506,7 +471,8 @@ while [[ $# -gt 0 ]] ; do help_cmdline=true ;; start|stop|restart|setup|status) - operations+=("$arg") + [[ -z $operation ]] || { gui=false error "Multiple operations are not supported." ; exit 1 ; } + operation=$arg ;; *) gui=false error "Unsupported argument (try \"--help\")" @@ -518,16 +484,6 @@ done ## # Configuration -_ssh_arguments=( - -o - PasswordAuthentication=no -) - -if [[ -n $PULSEAUDIO_TCP_SSH_ADDARGS ]] ; then - read -r -a _ssh_additional_arguments <<< "$PULSEAUDIO_TCP_SSH_ADDARGS" - _ssh_arguments+=("${_ssh_additional_arguments[@]}") -fi - config_dir="$HOME"/.config/pulseaudio-tcp config=$config_dir/config.inc.sh @@ -560,46 +516,45 @@ fi ## # Main Program -for operation in "${operations[@]}" ; do - rv=0 +rv=0 - if [[ "$operation" != setup ]] ; then - if ! test -e "$config" ; then - error "Configfile $config does not exist (use \"$0 setup\" first)." - rv=1 - elif ! test -r "$config" ; then - error "Configfile $config is not readable." - rv=1 - elif ! test -f "$config" ; then - error "Configfile $config is not a regular file." - rv=1 - else - . "$config" +if test "$operation" = setup ; then + info "Entering setup mode ..." +else + if ! test -e "$config" ; then + error "Configfile $config does not exist (use \"$0 setup\" first)." + rv=1 + elif ! test -r "$config" ; then + error "Configfile $config is not readable." + rv=1 + elif ! test -f "$config" ; then + error "Configfile $config is not a regular file." + rv=1 + else + . "$config" - if [[ -z $remote_ip ]] ; then - error "\"remote_ip=\" not set in configfile $config." - rv=1 - elif [[ -z $remote_user ]] ; then - error "\"remote_user=\" not set in configfile $config." - rv=1 - fi + if [[ -z $remote_ip ]] ; then + error "\"remote_ip=\" not set in configfile $config." + rv=1 + elif [[ -z $remote_user ]] ; then + error "\"remote_user=\" not set in configfile $config." + rv=1 fi - - required_cmds=( jq pactl ssh ) - - for exe in "${required_cmds[@]}" ; do - if [[ -z $(type -p "$exe") ]] ; then - error "Required executable \"$exe\" not found." - rv=1 - fi - done fi - if [[ $rv -ne 0 ]] ; then - error "Preliminary checks failed, skipping operation." - break - fi + required_cmds=( jq pactl ssh ) + for exe in "${required_cmds[@]}" ; do + if [[ -z $(type -p "$exe") ]] ; then + error "Required executable \"$exe\" not found." + rv=1 + fi + done +fi + +if [[ $rv -ne 0 ]] ; then + error "Preliminary checks failed, skipping operation." +else case "$operation" in setup) do_setup @@ -627,8 +582,6 @@ for operation in "${operations[@]}" ; do rv=1 ;; esac - - [[ $rv -ne 0 ]] && break -done +fi exit "$rv" diff --git a/pulseaudio-tcp.bash_completion b/pulseaudio-tcp.bash_completion index 962aea1..8d8568a 100644 --- a/pulseaudio-tcp.bash_completion +++ b/pulseaudio-tcp.bash_completion @@ -1,27 +1,34 @@ _pulseaudio_tcp_completions() { local \ command_list \ + command_pattern \ commands \ cur \ option_list \ options \ word - options=( "--debug" "--help" "--no-gui" "--" ) + options=( "--debug" "--help" "--no-gui" ) commands=( "start" "stop" "status" "setup" "restart" ) cur=${COMP_WORDS[COMP_CWORD]} - more_options=true for word in "${COMP_WORDS[@]}" ; do [[ $word = "$cur" ]] && continue - [[ $word = -- ]] && more_options=false options=("${options[@]/$word}") commands=("${commands[@]/$word}") done - "$more_options" && option_list="${options[*]}" - command_list="${commands[*]}" + option_list="${options[*]}" + + printf -v command_pattern "%s|" "${commands[@]}" + command_pattern="(${command_pattern%?})" + + if [[ ${COMP_WORDS[*]} =~ $command_pattern ]] ; then + command_list="" + else + command_list="${commands[*]}" + fi mapfile -t COMPREPLY < <( compgen -W "$option_list $command_list" -- "$cur")