diff --git a/rofi-pulse-sink.sh b/rofi-pulse-sink.sh index 180f476..34db9cc 100755 --- a/rofi-pulse-sink.sh +++ b/rofi-pulse-sink.sh @@ -131,6 +131,42 @@ Error in ${RED}pacmd list-sinks${COLOR_DEBUG} command." return "${return_get_pulseaudio_sink_list}" +} +# }}} +get_pulseaudio_current_sink() { # {{{ + + ## Return False by default + return_get_pulseaudio_current_sink="1" + + pa_current_sink_name=$(pactl info | awk '/Default Sink:/ { print $NF }') + + ## If variable for current default sink name contains something + if printf '%b' "${pa_current_sink_name}" | grep --silent -- "."; then + debug_message "get_pulseaudio_current_sink − \ +PulseAudio current default sink name: ${RED}${pa_current_sink_name}${COLOR_DEBUG}." + + pa_current_sink_description=$(pactl list sinks \ + | grep --after-context=1 -- "Name: ${pa_current_sink_name}" \ + | sed --silent 's/^.*Description: \(.*\)/\1/p') + + ### If variable for current default sink description contains something + if printf '%b' "${pa_current_sink_description}" | grep --silent -- "."; then + debug_message "get_pulseaudio_current_sink − \ +PulseAudio current deault sink description: ${RED}${pa_current_sink_description}${COLOR_DEBUG}." + return_get_pulseaudio_current_sink="0" + else + debug_message "get_pulseaudio_current_sink − \ +Can't get PulseAudio current deault sink description (got: ${pa_current_sink_description})." + return_get_pulseaudio_current_sink="1" + fi + else + debug_message "get_pulseaudio_current_sink − \ +Can't get PulseAudio current sink name (got: ${pa_current_sink_name})." + return_get_pulseaudio_current_sink="1" + fi + + return "${return_get_pulseaudio_current_sink}" + } # }}} choose_pulseaudio_sink() { # {{{ @@ -141,7 +177,7 @@ choose_pulseaudio_sink() { # {{{ debug_message "choose_pulseaudio_sink − \ Display PulseAudio sinks list with rofi to select one." - choosen_sink=$(rofi -location 2 -lines 4 -no-auto-select -i -dmenu -p "Choose new default output sink for PulseAudio" -color-enabled -color-normal "${BLACK},${BLUE},${BLACK},${BLUE},${BLACK}" -color-window "${BLACK},${BLACK}" < "${pa_sink_list_path}") + choosen_sink=$(rofi -location 2 -lines 4 -no-auto-select -i -dmenu -p "New output sink for PulseAudio (current: ${pa_current_sink_description:-Not available})" -color-enabled -color-normal "${BLACK},${BLUE},${BLACK},${BLUE},${BLACK}" -color-window "${BLACK},${BLACK}" < "${pa_sink_list_path}") choosen_sink_index=$(printf -- '%s' "${choosen_sink}" | cut --delimiter=" " --field=1) choosen_sink_description=$(printf -- '%s' "${choosen_sink}" | cut --delimiter=" " --field=2-) @@ -204,6 +240,11 @@ main() { # {{{ get_pulseaudio_sink_list \ || error_message "Can't get the PulseAudio sinks list. Please use --debug option." 1 ## }}} + ## Try to get current default sink {{{ + ### OR just display debug message + get_pulseaudio_current_sink \ + || debug_message "Can't get the PulseAudio current default sink." + ## }}} ## Choose a sink with rofi {{{ ### OR Exit with error message choose_pulseaudio_sink \