From 51a732d37983f115cf68e9c6cd63298b099413af Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Mon, 9 Nov 2020 22:01:01 -0700 Subject: [PATCH] Add zsh completions --- data/meson.build | 5 ++++ data/playerctl.zsh | 62 ++++++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 1 + 3 files changed, 68 insertions(+) create mode 100644 data/playerctl.zsh diff --git a/data/meson.build b/data/meson.build index da0b093..9f69243 100644 --- a/data/meson.build +++ b/data/meson.build @@ -26,3 +26,8 @@ if get_option('bash-completions') install_data(bash_files, install_dir: bash_install_dir) endif + +if get_option('zsh-completions') + zsh_install_dir = join_paths(datadir, 'zsh', 'site-functions') + install_data('playerctl.zsh', install_dir: zsh_install_dir, rename: '_playerctl') +endif diff --git a/data/playerctl.zsh b/data/playerctl.zsh new file mode 100644 index 0000000..c762da7 --- /dev/null +++ b/data/playerctl.zsh @@ -0,0 +1,62 @@ +#compdef playerctl + +typeset -A opt_args +__playerctl() { + command playerctl "$@" 2>/dev/null +} + +__playerctl_ctx() { + local -a player_opts=( + ${(kv)opt_args[(I)-p|--player]} + ${(kv)opt_args[(I)-i|--ignore-player]} + ${(kv)opt_args[(I)-a|--all-players]} + ) + __playerctl "$opt_args[@]" "$@" +} + +local -a playercmd_loop=(/$'(none|track|playlist)\0'/ ':(none track playlist)') +local -a playercmd_shuffle=(/$'(on|off)\0'/ ':(on off)') + +(( $+functions[_playerctl_players] )) || +_playerctl_players() { + local -a players=( ${(@f)"$(__playerctl --list-all)"} ) + players+=( "%all" ) + compadd "$@" -a players +} + +(( $+functions[_playerctl_metadata_keys] )) || +_playerctl_metadata_keys() { + local -a metadata=( ${(@f)"$(__playerctl_ctx metadata)"} ) + local -a keys=( ${${metadata#* }%% *} ) + _multi_parts "$@" -i ":" keys +} +local -a playerctl_command_metadata_keys=(/$'[^\0]#\0'/ ':keys:key:_playerctl_metadata_keys') + +local -a playerctl_command +_regex_words commands 'playerctl command' \ + 'play:Command the player to play' \ + 'pause:Command the player to pause' \ + 'play-pause:Command the player to toggle between play/pause' \ + 'stop:Command the player to stop' \ + 'next:Command the player to skip to the next track' \ + 'previous:Command the player to skip to the previous track' \ + 'position:Command the palyer to go or seek to the position' \ + 'volume:Print or set the volume level from 0.0 to 1.0' \ + 'status:Get the play status of the player' \ + 'metadata:Print the metadata information for the current track:$playerctl_command_metadata_keys' \ + 'open:Command the player to open the given URI' \ + 'loop:Print or set the loop status:$playercmd_loop' \ + 'shuffle:Print or set the shuffle status:$playercmd_shuffle' +playerctl_command=( /$'[^\0]#\0'/ "$reply[@]" ) +_regex_arguments _playerctl_command "$playerctl_command[@]" + +_arguments -S -s\ + '(-h --help)'{-h,--help}'[Show help message and quit]' \ + '(-v --version)'{-v,--version}'[Print version information and quit]' \ + '(-l --list-all)'{-l,--list-all}'[List all available players]' \ + '(-F, --follow)'{-F,--follow}'[Bock and append the query to output when it changes]' \ + '(-f --format)'{-f,--format=}'[Format string for printing properties and metadata]' \ + '(-i --ignore-player)'{-i,--ignore-player=}'[Comma separated list of players to ignore]:players:_sequence _playerctl_players' \ + '(-a --all-players)'{-a,--all-players}'[Control all players instead of just the first]' \ + '(-p --player)'{-p,--player=}'[Comma separated list of players to control]:players:_sequence _playerctl_players' \ + '*::playerctl command:= _playerctl_command' diff --git a/meson_options.txt b/meson_options.txt index 0ab809f..38ef4ee 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,4 @@ option('gtk-doc', type: 'boolean', value: true, description: 'build docs') option('introspection', type: 'boolean', value: true, description: 'build gir data') option('bash-completions', type: 'boolean', value: false, description: 'Install bash shell completions.') +option('zsh-completions', type: 'boolean', value: false, description: 'Install zsh shell completions.')