From 9140fc79318c217d8b3ca08f2d67fbf71af6376f Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 6 Dec 2020 22:54:41 +0900 Subject: [PATCH] pactl completions: guard call to other pulseaudio tools (#7532) At least on Arch Linux, pacmd and pulseaudio aren't necessarily available just because pactl is (pipewire is now a thing, and it installs libpulse but not pulseaudio) --- share/completions/pactl.fish | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/share/completions/pactl.fish b/share/completions/pactl.fish index 168e0dc42..4efc895b0 100644 --- a/share/completions/pactl.fish +++ b/share/completions/pactl.fish @@ -5,14 +5,18 @@ # TODO: Moar commands # set-port-latency-offset set-sink-formats - -# HACK: This is the list of commands from pacmd - used so we can use complete -w there -set -l commands (pacmd help | string match -r '^ +[-\w]+' | string trim) # These are the actual commands for pactl - we complete only these, and then the cmd commands in that completion set -l ctlcommands stat info list exit {upload,play,remove}-sample {load,unload}-module \ move-{sink-input,source-output} suspend-{sink,source} set-{card-profile,default-sink,sink-port,source-port,port-latency-offset} \ set-{sink,source,sink-input,source-output}-{volume,mute} set-sink-formats subscribe +# HACK: This is the list of commands from pacmd - used so we can use complete -w there +if command -sq pacmd + set commands (pacmd help | string match -r '^ +[-\w]+' | string trim) +else + set commands $ctlcommands +end + function __fish_pa_complete_type pactl list short $argv # The default is to show the number, then the name and then some info - also show the name, then the number as it's a bit friendlier @@ -36,13 +40,15 @@ end # This is needed to filter out loaded modules function __fish_pa_complete_unloaded_modules - # We need to get just the module names - set -l loaded (__fish_pa_print_type modules | string replace -r '^\w*\t([-\w]+).*' '$1') - pulseaudio --dump-modules | while read -l name description - # This is a potential source of slowness, but on my system it's instantaneous - # with 73 modules - if not contains -- $name $loaded - printf "%s\t%s\n" $name $description + if command -sq pulseaudio + # We need to get just the module names + set -l loaded (__fish_pa_print_type modules | string replace -r '^\w*\t([-\w]+).*' '$1') + pulseaudio --dump-modules | while read -l name description + # This is a potential source of slowness, but on my system it's instantaneous + # with 73 modules + if not contains -- $name $loaded + printf "%s\t%s\n" $name $description + end end end end