New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wpctl
completions
#10043
Add wpctl
completions
#10043
Conversation
share/completions/wpctl.fish
Outdated
end | ||
|
||
function __wpctl_command_shape | ||
set -l shape (string split --no-empty " " -- $argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary - you're already passing these as a list, so you can just use $argv directly.
share/completions/wpctl.fish
Outdated
if string match -- '-*' $arg | ||
set -e command[$i] | ||
else | ||
set i (math $i + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop can just be
set -l command (string match -v -- '-*' $command)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not that that's great - you typically would want to use argparse
here, but it is equivalent to your loop)
complete -c wpctl -n "__fish_seen_subcommand_from set-mute" -s p -l pid -d "Selects all nodes associated to the given PID number" | ||
|
||
complete -c wpctl -n __wpctl_command_shape -a "$commands" | ||
complete -c wpctl -n '__wpctl_command_shape "*"' -n "__fish_seen_subcommand_from get-volume inspect set-volume set-mute set-profile" -a "@DEFAULT_AUDIO_SOURCE@" -d "Default Microphone" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a placeholder or the actual argument wpctl expects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is a valid argument. @DEFAULT_*@
is mapped to the current default nodes
share/completions/wpctl.fish
Outdated
complete -c wpctl -n "__fish_seen_subcommand_from inspect" -s r -l referenced -d "Show objects that are referenced in properties" | ||
complete -c wpctl -n "__fish_seen_subcommand_from inspect" -s a -l associated -d "Show associated objects" | ||
complete -c wpctl -n "__fish_seen_subcommand_from set-volume" -s p -l pid -d "Selects all nodes associated to the given PID number" | ||
complete -c wpctl -n "__fish_seen_subcommand_from set-volume" -s l -l limit -d "Limits the final volume percentage to below this value. (floating point, 1.0 is 100%)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description is a mouthful - "Limit volume to between 0.0 and 1.0".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could set it higher than 1.0 for audio amplification, but we could remove the floating point bit, as that is implied from wpctl get-volume
output
share/completions/wpctl.fish
Outdated
complete -c wpctl -n "__fish_seen_subcommand_from status" -s n -l name -d "Display device and node names instead of descriptions" | ||
complete -c wpctl -n "__fish_seen_subcommand_from inspect" -s r -l referenced -d "Show objects that are referenced in properties" | ||
complete -c wpctl -n "__fish_seen_subcommand_from inspect" -s a -l associated -d "Show associated objects" | ||
complete -c wpctl -n "__fish_seen_subcommand_from set-volume" -s p -l pid -d "Selects all nodes associated to the given PID number" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"PID" is always a number, no need for "PID number".
share/completions/wpctl.fish
Outdated
|
||
function __wpctl_command_shape | ||
set -l shape (string split --no-empty " " -- $argv) | ||
set command (commandline -poc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set -l
, always.
share/completions/wpctl.fish
Outdated
complete -c wpctl -n '__wpctl_command_shape "*"' -n "__fish_seen_subcommand_from inspect set-profile" -a "@DEFAULT_VIDEO_SOURCE@" -d "Default Camera" | ||
complete -c wpctl -n '__wpctl_command_shape "*"' -n "__fish_seen_subcommand_from get-volume inspect set-volume set-mute set-profile" -a "(__wpctl_get_nodes Audio Sources) (__wpctl_get_nodes Audio Sinks)" | ||
complete -c wpctl -n '__wpctl_command_shape "*"' -n "__fish_seen_subcommand_from inspect set-profile" -a "(__wpctl_get_nodes Audio Sources) (__wpctl_get_nodes Audio Sinks) (__wpctl_get_nodes Video Source)" | ||
complete -c wpctl -n '__wpctl_command_shape set-mute "*"' -a 0\n1\ntoggle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can use spaces - -a '0 1 toggle'
. A bit nicer to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally forgot you could have it space separated
share/completions/wpctl.fish
Outdated
set -l commands status get-volume inspect set-default set-volume set-mute set-profile clear-default | ||
|
||
function __wpctl_get_nodes -a section -a type | ||
for node in (string match -r " ├─ $type:.*(?:\n │.*)+" "$(string match -r "$section*(?:\n [├│└].*)*" "$(wpctl status)")" | string match -rg '^ │[ \*]{6}([^\[]*)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty clever, but in a way that tells me there should be a better way to get this information - wpctl status
isn't made for parsing.
Case in point: This doesn't work for me. I run __wpctl_get_nodes Audio Sources
and it doesn't return anything.
This is because string match -r "$section*(?:\n [├│└].*)*" "$(wpctl status)"
only matches the string "Audio".
Instead, I would try it with a while-read-loop like this:
set -l havesection
set -l havetype
wpctl status | while read -l line
if set -q havesection[1]
test -z "$line"; and break
if set -q havetype[1]
string match -rq '^\s*\│\s*$' -- $line; and break
echo $line
else
string match -q "*$type*" -- $line
and set havetype 1
end
else
string match -q "$section*" -- $line
and set havesection 1
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the write-up
Thanks, merged! |
Description
Added completions for WirePlumber Control CLI
wpctl
TODOs: