2016-01-15 04:21:54 +08:00
|
|
|
# The control program for pulseaudio
|
|
|
|
# See not just pactl(1) but also pulse-cli-syntax(1)
|
|
|
|
# Note: Streams are called "sink-input" (for playback) and "source-output" (for recording)
|
|
|
|
|
|
|
|
# TODO: Moar commands
|
2016-01-15 05:21:50 +08:00
|
|
|
# set-port-latency-offset set-sink-formats
|
2016-01-15 04:21:54 +08:00
|
|
|
|
2016-01-15 06:31:17 +08:00
|
|
|
|
|
|
|
# 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 \
|
2019-05-05 18:53:09 +08:00
|
|
|
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
|
2016-01-15 04:21:54 +08:00
|
|
|
|
|
|
|
function __fish_pa_complete_type
|
2019-05-05 18:53:09 +08:00
|
|
|
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
|
|
|
|
pactl list short $argv | string replace -r '(\w+)\t([-\w]+)' '$2\t$1'
|
2016-01-15 04:21:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_pa_print_type
|
2019-05-05 18:53:09 +08:00
|
|
|
pactl list short $argv
|
|
|
|
# Pa allows both a numerical index and a name
|
|
|
|
pactl list short $argv | string replace -r '(\w+)\t.*' '$1'
|
2017-01-16 06:51:10 +08:00
|
|
|
end
|
2016-01-15 05:21:50 +08:00
|
|
|
|
|
|
|
function __fish_pa_list_ports
|
2019-05-05 18:53:09 +08:00
|
|
|
# Yes, this is localized
|
|
|
|
env LC_ALL=C pactl list cards 2>/dev/null | sed -n -e '/Ports:/,$p' | string match -r '^\t\t\w.*$' | string replace -r '\s+([-+\w:]+): (\w.+)' '$1\t$2'
|
2016-01-15 05:21:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_pa_list_profiles
|
2019-05-05 18:53:09 +08:00
|
|
|
env LC_ALL=C pactl list cards 2>/dev/null | sed -n -e '/Profiles:/,/Active Profile/p' | string match -r '\t\t.*' | string replace -r '\s+([-+\w:]+): (\w.+)' '$1\t$2'
|
2016-01-15 05:21:50 +08:00
|
|
|
end
|
|
|
|
|
2016-01-15 05:36:50 +08:00
|
|
|
# This is needed to filter out loaded modules
|
|
|
|
function __fish_pa_complete_unloaded_modules
|
2019-05-05 18:53:09 +08:00
|
|
|
# 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 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
|
2016-01-15 05:36:50 +08:00
|
|
|
end
|
|
|
|
|
2020-03-07 14:56:26 +08:00
|
|
|
complete -f -c pactl
|
2016-01-15 06:31:17 +08:00
|
|
|
complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a "$ctlcommands"
|
2016-01-15 04:21:54 +08:00
|
|
|
|
|
|
|
complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a stat -d 'Show statistics about memory usage'
|
|
|
|
complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a info -d 'Show info about the daemon'
|
|
|
|
complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a list -d 'Show all loaded things of the specified type'
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from list" -a "modules sinks sources sink-inputs source-outputs clients samples cards"
|
2020-03-10 02:36:12 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from list" -a short -d "Show shorter output"
|
2016-01-15 04:21:54 +08:00
|
|
|
complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a exit -d 'Ask the daemon to exit'
|
|
|
|
|
|
|
|
complete -c pactl -n "not __fish_seen_subcommand_from $commands" -a upload-sample -d 'Upload a file to the sample cache'
|
|
|
|
complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a play-sample -d 'Play a sample from the cache'
|
|
|
|
complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a remove-sample -d 'Remove a sample from the cache'
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from play-sample remove-sample" -a '(__fish_pa_complete_type samples)'
|
|
|
|
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from unload-module" -a '(__fish_pa_complete_type modules)'
|
2016-01-15 05:36:50 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from load-module" -a '(__fish_pa_complete_unloaded_modules)'
|
2016-01-15 04:21:54 +08:00
|
|
|
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from move-sink-input; and not __fish_seen_subcommand_from (__fish_pa_print_type sink-inputs)" \
|
2019-05-05 18:53:09 +08:00
|
|
|
-a '(__fish_pa_complete_type sink-inputs)'
|
2016-01-15 04:21:54 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from move-sink-input; and __fish_seen_subcommand_from (__fish_pa_print_type sink-inputs)" \
|
2019-05-05 18:53:09 +08:00
|
|
|
-a '(__fish_pa_complete_type sinks)'
|
2016-01-15 04:21:54 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from move-source-output; and not __fish_seen_subcommand_from (__fish_pa_print_type source-outputs)" \
|
2019-05-05 18:53:09 +08:00
|
|
|
-a '(__fish_pa_complete_type source-outputs)'
|
2016-01-15 04:21:54 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from move-source-output; and __fish_seen_subcommand_from (__fish_pa_print_type source-outputs)" \
|
2019-05-05 18:53:09 +08:00
|
|
|
-a '(__fish_pa_complete_type sources)'
|
2016-01-15 04:21:54 +08:00
|
|
|
|
|
|
|
# Suspend
|
|
|
|
for t in source sink
|
2019-05-05 18:53:09 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from suspend-$t; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
|
|
|
-a "(__fish_pa_complete_type "$t"s)"
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from suspend-$t; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
2020-03-10 02:36:12 +08:00
|
|
|
-a '0 false off' -d Resume
|
2019-05-05 18:53:09 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from suspend-$t; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
2020-03-10 02:36:12 +08:00
|
|
|
-a '1 true on' -d Suspend
|
2019-05-05 18:53:09 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-port; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
|
|
|
-a "(__fish_pa_complete_type "$t"s)"
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-port; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
|
|
|
-a "(__fish_pa_list_ports)"
|
2016-01-15 04:21:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Volume and mute
|
|
|
|
for t in source sink source-output sink-input
|
2019-05-05 18:53:09 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-volume; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
|
|
|
-a "(__fish_pa_complete_type "$t"s)"
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-volume; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
|
|
|
-a "(seq 0 100)%"
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
|
|
|
-a "(__fish_pa_complete_type "$t"s)"
|
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
2020-03-10 02:36:12 +08:00
|
|
|
-a "1 true on" -d Muted
|
2019-05-05 18:53:09 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
2020-03-10 02:36:12 +08:00
|
|
|
-a "0 false off" -d Unmuted
|
2019-05-05 18:53:09 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
|
2020-03-10 02:36:12 +08:00
|
|
|
-a toggle
|
2016-01-15 04:21:54 +08:00
|
|
|
end
|
|
|
|
|
2016-01-15 05:21:50 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-card-profile; and not __fish_seen_subcommand_from (__fish_pa_print_type cards)" \
|
2019-05-05 18:53:09 +08:00
|
|
|
-a "(__fish_pa_complete_type cards)"
|
2016-01-15 05:21:50 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-card-profile; and __fish_seen_subcommand_from (__fish_pa_print_type cards)" \
|
2019-05-05 18:53:09 +08:00
|
|
|
-a "(__fish_pa_list_profiles)"
|
2016-01-15 05:21:50 +08:00
|
|
|
|
2016-01-15 04:21:54 +08:00
|
|
|
complete -f -c pactl -n "__fish_seen_subcommand_from set-default-sink" -a "(__fish_pa_complete_type sinks)"
|
|
|
|
|
|
|
|
complete -f -c pactl -l version -d 'Print a short version and exit'
|
|
|
|
complete -f -c pactl -s h -l help -d 'Print help text and exit'
|