fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Fabian Boehmcompletions/pactl: Fix matching objects5f26c56ed

master
7.0 KiB121 linesraw
1# The control program for pulseaudio
2# See not just pactl(1) but also pulse-cli-syntax(1)
3# Note: Streams are called "sink-input" (for playback) and "source-output" (for recording)
4
5# TODO: Moar commands
6# set-port-latency-offset set-sink-formats
7
8# These are the actual commands for pactl - we complete only these, and then the cmd commands in that completion
9set -l ctlcommands stat info list exit {upload,play,remove}-sample {load,unload}-module \
10    move-{sink-input,source-output} suspend-{sink,source} set-{card-profile,default-sink,sink-port,source-port,port-latency-offset} \
11    set-{sink,source,sink-input,source-output}-{volume,mute} set-sink-formats subscribe
12
13# HACK: This is the list of commands from pacmd - used so we can use complete -w there
14if command -sq pacmd
15    set commands (pacmd help 2>/dev/null | string match -r '^ +[-\w]+' | string trim)
16else
17    set commands $ctlcommands
18end
19
20function __fish_pa_complete_type
21    # Print a completion candidate for the object type (like "card" or "sink"),
22    # with a description.
23    # Pa allows both a numerical index and a name
24    pactl list short $argv | string replace -rf '(\d+)\s+(\S+)(\s+.*)?' '$2\t$1$3\n$1\t$2$3'
25end
26
27function __fish_pa_print_type
28    # Print just the object, without description
29    __fish_pa_complete_type $argv | string replace -r '\t.*' ''
30end
31
32function __fish_pa_list_ports
33    # Yes, this is localized
34    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'
35end
36
37function __fish_pa_list_profiles
38    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'
39end
40
41# This is needed to filter out loaded modules
42function __fish_pa_complete_unloaded_modules
43    if command -sq pulseaudio
44        # We need to get just the module names
45        set -l loaded (__fish_pa_print_type modules | string replace -r '^\w*\t([-\w]+).*' '$1')
46        pulseaudio --dump-modules | while read -l name description
47            # This is a potential source of slowness, but on my system it's instantaneous
48            # with 73 modules
49            if not contains -- $name $loaded
50                printf "%s\t%s\n" $name $description
51            end
52        end
53    end
54end
55
56complete -f -c pactl
57complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a "$ctlcommands"
58
59complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a stat -d 'Show statistics about memory usage'
60complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a info -d 'Show info about the daemon'
61complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a list -d 'Show all loaded things of the specified type'
62complete -f -c pactl -n "__fish_seen_subcommand_from list" -a "modules sinks sources sink-inputs source-outputs clients samples cards"
63complete -f -c pactl -n "__fish_seen_subcommand_from list" -a short -d "Show shorter output"
64complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a exit -d 'Ask the daemon to exit'
65
66complete -c pactl -n "not __fish_seen_subcommand_from $commands" -a upload-sample -d 'Upload a file to the sample cache'
67complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a play-sample -d 'Play a sample from the cache'
68complete -f -c pactl -n "not __fish_seen_subcommand_from $commands" -a remove-sample -d 'Remove a sample from the cache'
69complete -f -c pactl -n "__fish_seen_subcommand_from play-sample remove-sample" -a '(__fish_pa_complete_type samples)'
70
71complete -f -c pactl -n "__fish_seen_subcommand_from unload-module" -a '(__fish_pa_complete_type modules)'
72complete -f -c pactl -n "__fish_seen_subcommand_from load-module" -a '(__fish_pa_complete_unloaded_modules)'
73
74complete -f -c pactl -n "__fish_seen_subcommand_from move-sink-input; and not __fish_seen_subcommand_from (__fish_pa_print_type sink-inputs)" \
75    -a '(__fish_pa_complete_type sink-inputs)'
76complete -f -c pactl -n "__fish_seen_subcommand_from move-sink-input; and __fish_seen_subcommand_from (__fish_pa_print_type sink-inputs)" \
77    -a '(__fish_pa_complete_type sinks)'
78complete -f -c pactl -n "__fish_seen_subcommand_from move-source-output; and not __fish_seen_subcommand_from (__fish_pa_print_type source-outputs)" \
79    -a '(__fish_pa_complete_type source-outputs)'
80complete -f -c pactl -n "__fish_seen_subcommand_from move-source-output; and __fish_seen_subcommand_from (__fish_pa_print_type source-outputs)" \
81    -a '(__fish_pa_complete_type sources)'
82
83# Suspend
84for t in source sink
85    complete -f -c pactl -n "__fish_seen_subcommand_from suspend-$t; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
86        -a "(__fish_pa_complete_type "$t"s)"
87    complete -f -c pactl -n "__fish_seen_subcommand_from suspend-$t; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
88        -a '0 false off' -d Resume
89    complete -f -c pactl -n "__fish_seen_subcommand_from suspend-$t; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
90        -a '1 true on' -d Suspend
91    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-port; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
92        -a "(__fish_pa_complete_type "$t"s)"
93    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-port; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
94        -a "(__fish_pa_list_ports)"
95end
96
97# Volume and mute
98for t in source sink source-output sink-input
99    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-volume; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
100        -a "(__fish_pa_complete_type "$t"s)"
101    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-volume; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
102        -a "(seq 0 100)%"
103    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and not __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
104        -a "(__fish_pa_complete_type "$t"s)"
105    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
106        -a "1 true on" -d Muted
107    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
108        -a "0 false off" -d Unmuted
109    complete -f -c pactl -n "__fish_seen_subcommand_from set-$t-mute; and __fish_seen_subcommand_from (__fish_pa_print_type "$t"s)" \
110        -a toggle
111end
112
113complete -f -c pactl -n "__fish_seen_subcommand_from set-card-profile; and not __fish_seen_subcommand_from (__fish_pa_print_type cards)" \
114    -a "(__fish_pa_complete_type cards)"
115complete -f -c pactl -n "__fish_seen_subcommand_from set-card-profile; and __fish_seen_subcommand_from (__fish_pa_print_type cards)" \
116    -a "(__fish_pa_list_profiles)"
117
118complete -f -c pactl -n "__fish_seen_subcommand_from set-default-sink" -a "(__fish_pa_complete_type sinks)"
119
120complete -f -c pactl -l version -d 'Print a short version and exit'
121complete -f -c pactl -s h -l help -d 'Print help text and exit'