diff --git a/src/tools/meson.build b/src/tools/meson.build index 5ed224e7..ffd5f155 100644 --- a/src/tools/meson.build +++ b/src/tools/meson.build @@ -4,6 +4,11 @@ executable('wpctl', dependencies : [gobject_dep, gio_dep, wp_dep, pipewire_dep, libintl_dep], ) +install_data('shell-completion/wpctl.bash', + install_dir: get_option('datadir') / 'bash-completion/completions', + rename: 'wpctl' +) + install_data('shell-completion/wpctl.zsh', install_dir: get_option('datadir') / 'zsh/site-functions', rename: '_wpctl' diff --git a/src/tools/shell-completion/wpctl.bash b/src/tools/shell-completion/wpctl.bash new file mode 100644 index 00000000..dc3d1783 --- /dev/null +++ b/src/tools/shell-completion/wpctl.bash @@ -0,0 +1,30 @@ +_wpctl_pw_defaults() { + local defaults="@DEFAULT_SINK@ @DEFAULT_AUDIO_SINK@ @DEFAULT_SOURCE@ + @DEFAULT_AUDIO_SOURCE@ @DEFAULT_VIDEO_SOURCE@" + COMPREPLY+=($(compgen -W "$defaults" -- "$cur")) +} + +_wpctl() { + local cur prev words cword + local commands="status get-volume inspect set-default set-volume set-mute + set-profile set-route clear-default settings set-log-level" + + _init_completion -n = || return + + if [[ ${#COMP_WORDS[@]} -eq 2 ]]; then + COMPREPLY=($(compgen -W "$commands" -- "$cur")) + return + fi + + case $prev in + get-volume | inspect | set-volume | set-mute | set-profile | set-route) + _wpctl_pw_defaults + ;; + + clear-default) + COMPREPLY+=($(compgen -W "0 1 2" -- "$cur")) + ;; + esac +} + +complete -F _wpctl wpctl