From 1059d878476c231f84ef9d3c2e8bcafaf978bc87 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 13 May 2026 11:27:16 +0200 Subject: Regenerate shell completions and install script fixes - Add hidden completions subcommand to CLI (developer use only) - Regenerate all completion scripts from current CLI structure - Add elvish and powershell completion scripts - install.sh: Fix rsp stop -> rsp stop-daemon, rsp start -> rsp start-daemon - install.sh: Install completions for user's current shell - install.sh: Zsh uses /usr/share/zsh/site-functions/_rsp directly --- completions/rsp.bash | 52 +++------ completions/rsp.elvish | 224 ++++++++++++++++++++++++++++++++++++ completions/rsp.fish | 59 +++++----- completions/rsp.powershell | 280 +++++++++++++++++++++++++++++++++++++++++++++ completions/rsp.zsh | 70 +++++------- install.sh | 40 ++++++- src/cli.rs | 43 ++++++- 7 files changed, 657 insertions(+), 111 deletions(-) create mode 100644 completions/rsp.elvish create mode 100644 completions/rsp.powershell diff --git a/completions/rsp.bash b/completions/rsp.bash index 4ea8603..1812802 100644 --- a/completions/rsp.bash +++ b/completions/rsp.bash @@ -1,14 +1,3 @@ -_rsp_play_query_completions() { - local cur="${COMP_WORDS[COMP_CWORD]}" - # Only do dynamic completion if COMPREPLY is empty (no flag matched) - # and the current word doesn't start with - - if [[ ${#COMPREPLY[@]} -eq 0 && "$cur" != -* ]]; then - local -a artists - artists=($(rsp play --list 2>/dev/null)) - COMPREPLY=( $(compgen -W "${artists[*]}" -- "$cur") ) - fi -} - _rsp() { local i cur prev opts cmd COMPREPLY=() @@ -63,8 +52,8 @@ _rsp() { rsp,shuffle) cmd="rsp__subcmd__shuffle" ;; - rsp,start) - cmd="rsp__subcmd__start" + rsp,start-daemon) + cmd="rsp__subcmd__start__subcmd__daemon" ;; rsp,status) cmd="rsp__subcmd__status" @@ -72,8 +61,8 @@ _rsp() { rsp,stop) cmd="rsp__subcmd__stop" ;; - rsp,stop-playback) - cmd="rsp__subcmd__stop__subcmd__playback" + rsp,stop-daemon) + cmd="rsp__subcmd__stop__subcmd__daemon" ;; rsp,toggle) cmd="rsp__subcmd__toggle" @@ -117,8 +106,8 @@ _rsp() { rsp__subcmd__help,shuffle) cmd="rsp__subcmd__help__subcmd__shuffle" ;; - rsp__subcmd__help,start) - cmd="rsp__subcmd__help__subcmd__start" + rsp__subcmd__help,start-daemon) + cmd="rsp__subcmd__help__subcmd__start__subcmd__daemon" ;; rsp__subcmd__help,status) cmd="rsp__subcmd__help__subcmd__status" @@ -126,8 +115,8 @@ _rsp() { rsp__subcmd__help,stop) cmd="rsp__subcmd__help__subcmd__stop" ;; - rsp__subcmd__help,stop-playback) - cmd="rsp__subcmd__help__subcmd__stop__subcmd__playback" + rsp__subcmd__help,stop-daemon) + cmd="rsp__subcmd__help__subcmd__stop__subcmd__daemon" ;; rsp__subcmd__help,toggle) cmd="rsp__subcmd__help__subcmd__toggle" @@ -184,7 +173,7 @@ _rsp() { case "${cmd}" in rsp) - opts="-h --help start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" + opts="-h --help start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -198,16 +187,12 @@ _rsp() { return 0 ;; rsp__subcmd__completions) - opts="-h --shell --help" + opts="-h --help [SHELL]" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 fi case "${prev}" in - --shell) - COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}")) - return 0 - ;; *) COMPREPLY=() ;; @@ -216,7 +201,7 @@ _rsp() { return 0 ;; rsp__subcmd__help) - opts="start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" + opts="start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -453,7 +438,7 @@ _rsp() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - rsp__subcmd__help__subcmd__start) + rsp__subcmd__help__subcmd__start__subcmd__daemon) opts="" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) @@ -495,7 +480,7 @@ _rsp() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - rsp__subcmd__help__subcmd__stop__subcmd__playback) + rsp__subcmd__help__subcmd__stop__subcmd__daemon) opts="" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) @@ -566,7 +551,7 @@ _rsp() { return 0 ;; rsp__subcmd__play) - opts="-i -n -l -L -h --now --next --last --list --help [QUERY]" + opts="-i -n -h --now --next --help [QUERY]" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -577,10 +562,7 @@ _rsp() { ;; esac COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - - # Dynamic artist/album completion for query argument - _rsp_play_query_completions -return 0 + return 0 ;; rsp__subcmd__previous) opts="-h --help" @@ -824,7 +806,7 @@ return 0 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - rsp__subcmd__start) + rsp__subcmd__start__subcmd__daemon) opts="-h --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) @@ -866,7 +848,7 @@ return 0 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - rsp__subcmd__stop__subcmd__playback) + rsp__subcmd__stop__subcmd__daemon) opts="-h --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) diff --git a/completions/rsp.elvish b/completions/rsp.elvish new file mode 100644 index 0000000..54ccdfe --- /dev/null +++ b/completions/rsp.elvish @@ -0,0 +1,224 @@ + +use builtin; +use str; + +set edit:completion:arg-completer[rsp] = {|@words| + fn spaces {|n| + builtin:repeat $n ' ' | str:join '' + } + fn cand {|text desc| + edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc + } + var command = 'rsp' + for word $words[1..-1] { + if (str:has-prefix $word '-') { + break + } + set command = $command';'$word + } + var completions = [ + &'rsp'= { + cand -h 'Print help' + cand --help 'Print help' + cand start-daemon 'Start the daemon' + cand stop-daemon 'Stop the daemon' + cand restart 'Restart the daemon (kill existing and start new)' + cand play 'Play a track, album, or artist' + cand pause 'Pause playback' + cand resume 'Resume playback' + cand toggle 'Toggle play/pause' + cand stop 'Stop playback' + cand next 'Skip to next track' + cand previous 'Skip to previous track' + cand volume 'Set volume (0-100)' + cand shuffle 'Shuffle mode' + cand queue 'Queue management' + cand status 'Show player status' + cand scan 'Scan music paths to populate database' + cand settings 'Settings management' + cand completions 'Generate shell completions (developer only)' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'rsp;start-daemon'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;stop-daemon'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;restart'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;play'= { + cand -i 'Add after current track and skip to it' + cand --now 'Add after current track and skip to it' + cand -n 'Add to queue after current track (don''t skip)' + cand --next 'Add to queue after current track (don''t skip)' + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;pause'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;resume'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;toggle'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;stop'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;next'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;previous'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;volume'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;shuffle'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;queue'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;status'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;scan'= { + cand --paths 'paths' + cand --force 'force' + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;settings'= { + cand -h 'Print help' + cand --help 'Print help' + cand get 'Get a setting value' + cand set 'Set a setting value' + cand list 'List all settings' + cand unset 'Unset a setting' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'rsp;settings;get'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;settings;set'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;settings;list'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;settings;unset'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;settings;help'= { + cand get 'Get a setting value' + cand set 'Set a setting value' + cand list 'List all settings' + cand unset 'Unset a setting' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'rsp;settings;help;get'= { + } + &'rsp;settings;help;set'= { + } + &'rsp;settings;help;list'= { + } + &'rsp;settings;help;unset'= { + } + &'rsp;settings;help;help'= { + } + &'rsp;completions'= { + cand -h 'Print help' + cand --help 'Print help' + } + &'rsp;help'= { + cand start-daemon 'Start the daemon' + cand stop-daemon 'Stop the daemon' + cand restart 'Restart the daemon (kill existing and start new)' + cand play 'Play a track, album, or artist' + cand pause 'Pause playback' + cand resume 'Resume playback' + cand toggle 'Toggle play/pause' + cand stop 'Stop playback' + cand next 'Skip to next track' + cand previous 'Skip to previous track' + cand volume 'Set volume (0-100)' + cand shuffle 'Shuffle mode' + cand queue 'Queue management' + cand status 'Show player status' + cand scan 'Scan music paths to populate database' + cand settings 'Settings management' + cand completions 'Generate shell completions (developer only)' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'rsp;help;start-daemon'= { + } + &'rsp;help;stop-daemon'= { + } + &'rsp;help;restart'= { + } + &'rsp;help;play'= { + } + &'rsp;help;pause'= { + } + &'rsp;help;resume'= { + } + &'rsp;help;toggle'= { + } + &'rsp;help;stop'= { + } + &'rsp;help;next'= { + } + &'rsp;help;previous'= { + } + &'rsp;help;volume'= { + } + &'rsp;help;shuffle'= { + } + &'rsp;help;queue'= { + } + &'rsp;help;status'= { + } + &'rsp;help;scan'= { + } + &'rsp;help;settings'= { + cand get 'Get a setting value' + cand set 'Set a setting value' + cand list 'List all settings' + cand unset 'Unset a setting' + } + &'rsp;help;settings;get'= { + } + &'rsp;help;settings;set'= { + } + &'rsp;help;settings;list'= { + } + &'rsp;help;settings;unset'= { + } + &'rsp;help;completions'= { + } + &'rsp;help;help'= { + } + ] + $completions[$command] +} diff --git a/completions/rsp.fish b/completions/rsp.fish index d0e391d..265fe37 100644 --- a/completions/rsp.fish +++ b/completions/rsp.fish @@ -25,14 +25,14 @@ function __fish_rsp_using_subcommand end complete -c rsp -n "__fish_rsp_needs_command" -s h -l help -d 'Print help' -complete -c rsp -n "__fish_rsp_needs_command" -f -a "start" -d 'Start the daemon' -complete -c rsp -n "__fish_rsp_needs_command" -f -a "stop" -d 'Stop the daemon' +complete -c rsp -n "__fish_rsp_needs_command" -f -a "start-daemon" -d 'Start the daemon' +complete -c rsp -n "__fish_rsp_needs_command" -f -a "stop-daemon" -d 'Stop the daemon' complete -c rsp -n "__fish_rsp_needs_command" -f -a "restart" -d 'Restart the daemon (kill existing and start new)' complete -c rsp -n "__fish_rsp_needs_command" -f -a "play" -d 'Play a track, album, or artist' complete -c rsp -n "__fish_rsp_needs_command" -f -a "pause" -d 'Pause playback' complete -c rsp -n "__fish_rsp_needs_command" -f -a "resume" -d 'Resume playback' complete -c rsp -n "__fish_rsp_needs_command" -f -a "toggle" -d 'Toggle play/pause' -complete -c rsp -n "__fish_rsp_needs_command" -f -a "stop-playback" -d 'Stop playback' +complete -c rsp -n "__fish_rsp_needs_command" -f -a "stop" -d 'Stop playback' complete -c rsp -n "__fish_rsp_needs_command" -f -a "next" -d 'Skip to next track' complete -c rsp -n "__fish_rsp_needs_command" -f -a "previous" -d 'Skip to previous track' complete -c rsp -n "__fish_rsp_needs_command" -f -a "volume" -d 'Set volume (0-100)' @@ -41,20 +41,18 @@ complete -c rsp -n "__fish_rsp_needs_command" -f -a "queue" -d 'Queue management complete -c rsp -n "__fish_rsp_needs_command" -f -a "status" -d 'Show player status' complete -c rsp -n "__fish_rsp_needs_command" -f -a "scan" -d 'Scan music paths to populate database' complete -c rsp -n "__fish_rsp_needs_command" -f -a "settings" -d 'Settings management' -complete -c rsp -n "__fish_rsp_needs_command" -f -a "completions" -d 'Generate shell completions and write to completions/ directory (bash, elvish, fish, powershell, zsh)' +complete -c rsp -n "__fish_rsp_needs_command" -f -a "completions" -d 'Generate shell completions (developer only)' complete -c rsp -n "__fish_rsp_needs_command" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' -complete -c rsp -n "__fish_rsp_using_subcommand start" -s h -l help -d 'Print help' -complete -c rsp -n "__fish_rsp_using_subcommand stop" -s h -l help -d 'Print help' +complete -c rsp -n "__fish_rsp_using_subcommand start-daemon" -s h -l help -d 'Print help' +complete -c rsp -n "__fish_rsp_using_subcommand stop-daemon" -s h -l help -d 'Print help' complete -c rsp -n "__fish_rsp_using_subcommand restart" -s h -l help -d 'Print help' -complete -c rsp -n "__fish_rsp_using_subcommand play" -s i -l now -d 'Play immediately (add after current and skip to it)' +complete -c rsp -n "__fish_rsp_using_subcommand play" -s i -l now -d 'Add after current track and skip to it' complete -c rsp -n "__fish_rsp_using_subcommand play" -s n -l next -d 'Add to queue after current track (don\'t skip)' -complete -c rsp -n "__fish_rsp_using_subcommand play" -s l -l last -d 'Add to end of queue (default)' -complete -c rsp -n "__fish_rsp_using_subcommand play" -s L -l list -d 'List available artists/albums' complete -c rsp -n "__fish_rsp_using_subcommand play" -s h -l help -d 'Print help' complete -c rsp -n "__fish_rsp_using_subcommand pause" -s h -l help -d 'Print help' complete -c rsp -n "__fish_rsp_using_subcommand resume" -s h -l help -d 'Print help' complete -c rsp -n "__fish_rsp_using_subcommand toggle" -s h -l help -d 'Print help' -complete -c rsp -n "__fish_rsp_using_subcommand stop-playback" -s h -l help -d 'Print help' +complete -c rsp -n "__fish_rsp_using_subcommand stop" -s h -l help -d 'Print help' complete -c rsp -n "__fish_rsp_using_subcommand next" -s h -l help -d 'Print help' complete -c rsp -n "__fish_rsp_using_subcommand previous" -s h -l help -d 'Print help' complete -c rsp -n "__fish_rsp_using_subcommand volume" -s h -l help -d 'Print help' @@ -79,30 +77,25 @@ complete -c rsp -n "__fish_rsp_using_subcommand settings; and __fish_seen_subcom complete -c rsp -n "__fish_rsp_using_subcommand settings; and __fish_seen_subcommand_from help" -f -a "list" -d 'List all settings' complete -c rsp -n "__fish_rsp_using_subcommand settings; and __fish_seen_subcommand_from help" -f -a "unset" -d 'Unset a setting' complete -c rsp -n "__fish_rsp_using_subcommand settings; and __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' -complete -c rsp -n "__fish_rsp_using_subcommand completions" -l shell -d 'Also print to stdout for a specific shell' -r -f -a "bash\t'' -elvish\t'' -fish\t'' -powershell\t'' -zsh\t''" complete -c rsp -n "__fish_rsp_using_subcommand completions" -s h -l help -d 'Print help' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "start" -d 'Start the daemon' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "stop" -d 'Stop the daemon' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "restart" -d 'Restart the daemon (kill existing and start new)' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "play" -d 'Play a track, album, or artist' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "pause" -d 'Pause playback' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "resume" -d 'Resume playback' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "toggle" -d 'Toggle play/pause' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "stop-playback" -d 'Stop playback' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "next" -d 'Skip to next track' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "previous" -d 'Skip to previous track' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "volume" -d 'Set volume (0-100)' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "shuffle" -d 'Shuffle mode' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "queue" -d 'Queue management' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "status" -d 'Show player status' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "scan" -d 'Scan music paths to populate database' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "settings" -d 'Settings management' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "completions" -d 'Generate shell completions and write to completions/ directory (bash, elvish, fish, powershell, zsh)' -complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start stop restart play pause resume toggle stop-playback next previous volume shuffle queue status scan settings completions help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "start-daemon" -d 'Start the daemon' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "stop-daemon" -d 'Stop the daemon' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "restart" -d 'Restart the daemon (kill existing and start new)' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "play" -d 'Play a track, album, or artist' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "pause" -d 'Pause playback' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "resume" -d 'Resume playback' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "toggle" -d 'Toggle play/pause' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "stop" -d 'Stop playback' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "next" -d 'Skip to next track' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "previous" -d 'Skip to previous track' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "volume" -d 'Set volume (0-100)' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "shuffle" -d 'Shuffle mode' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "queue" -d 'Queue management' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "status" -d 'Show player status' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "scan" -d 'Scan music paths to populate database' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "settings" -d 'Settings management' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "completions" -d 'Generate shell completions (developer only)' +complete -c rsp -n "__fish_rsp_using_subcommand help; and not __fish_seen_subcommand_from start-daemon stop-daemon restart play pause resume toggle stop next previous volume shuffle queue status scan settings completions help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' complete -c rsp -n "__fish_rsp_using_subcommand help; and __fish_seen_subcommand_from settings" -f -a "get" -d 'Get a setting value' complete -c rsp -n "__fish_rsp_using_subcommand help; and __fish_seen_subcommand_from settings" -f -a "set" -d 'Set a setting value' complete -c rsp -n "__fish_rsp_using_subcommand help; and __fish_seen_subcommand_from settings" -f -a "list" -d 'List all settings' diff --git a/completions/rsp.powershell b/completions/rsp.powershell new file mode 100644 index 0000000..58db681 --- /dev/null +++ b/completions/rsp.powershell @@ -0,0 +1,280 @@ + +using namespace System.Management.Automation +using namespace System.Management.Automation.Language + +Register-ArgumentCompleter -Native -CommandName 'rsp' -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $commandElements = $commandAst.CommandElements + $command = @( + 'rsp' + for ($i = 1; $i -lt $commandElements.Count; $i++) { + $element = $commandElements[$i] + if ($element -isnot [StringConstantExpressionAst] -or + $element.StringConstantType -ne [StringConstantType]::BareWord -or + $element.Value.StartsWith('-') -or + $element.Value -eq $wordToComplete) { + break + } + $element.Value + }) -join ';' + + $completions = @(switch ($command) { + 'rsp' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('start-daemon', 'start-daemon', [CompletionResultType]::ParameterValue, 'Start the daemon') + [CompletionResult]::new('stop-daemon', 'stop-daemon', [CompletionResultType]::ParameterValue, 'Stop the daemon') + [CompletionResult]::new('restart', 'restart', [CompletionResultType]::ParameterValue, 'Restart the daemon (kill existing and start new)') + [CompletionResult]::new('play', 'play', [CompletionResultType]::ParameterValue, 'Play a track, album, or artist') + [CompletionResult]::new('pause', 'pause', [CompletionResultType]::ParameterValue, 'Pause playback') + [CompletionResult]::new('resume', 'resume', [CompletionResultType]::ParameterValue, 'Resume playback') + [CompletionResult]::new('toggle', 'toggle', [CompletionResultType]::ParameterValue, 'Toggle play/pause') + [CompletionResult]::new('stop', 'stop', [CompletionResultType]::ParameterValue, 'Stop playback') + [CompletionResult]::new('next', 'next', [CompletionResultType]::ParameterValue, 'Skip to next track') + [CompletionResult]::new('previous', 'previous', [CompletionResultType]::ParameterValue, 'Skip to previous track') + [CompletionResult]::new('volume', 'volume', [CompletionResultType]::ParameterValue, 'Set volume (0-100)') + [CompletionResult]::new('shuffle', 'shuffle', [CompletionResultType]::ParameterValue, 'Shuffle mode') + [CompletionResult]::new('queue', 'queue', [CompletionResultType]::ParameterValue, 'Queue management') + [CompletionResult]::new('status', 'status', [CompletionResultType]::ParameterValue, 'Show player status') + [CompletionResult]::new('scan', 'scan', [CompletionResultType]::ParameterValue, 'Scan music paths to populate database') + [CompletionResult]::new('settings', 'settings', [CompletionResultType]::ParameterValue, 'Settings management') + [CompletionResult]::new('completions', 'completions', [CompletionResultType]::ParameterValue, 'Generate shell completions (developer only)') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') + break + } + 'rsp;start-daemon' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;stop-daemon' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;restart' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;play' { + [CompletionResult]::new('-i', '-i', [CompletionResultType]::ParameterName, 'Add after current track and skip to it') + [CompletionResult]::new('--now', '--now', [CompletionResultType]::ParameterName, 'Add after current track and skip to it') + [CompletionResult]::new('-n', '-n', [CompletionResultType]::ParameterName, 'Add to queue after current track (don''t skip)') + [CompletionResult]::new('--next', '--next', [CompletionResultType]::ParameterName, 'Add to queue after current track (don''t skip)') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;pause' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;resume' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;toggle' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;stop' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;next' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;previous' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;volume' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;shuffle' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;queue' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;status' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;scan' { + [CompletionResult]::new('--paths', '--paths', [CompletionResultType]::ParameterName, 'paths') + [CompletionResult]::new('--force', '--force', [CompletionResultType]::ParameterName, 'force') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;settings' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('get', 'get', [CompletionResultType]::ParameterValue, 'Get a setting value') + [CompletionResult]::new('set', 'set', [CompletionResultType]::ParameterValue, 'Set a setting value') + [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'List all settings') + [CompletionResult]::new('unset', 'unset', [CompletionResultType]::ParameterValue, 'Unset a setting') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') + break + } + 'rsp;settings;get' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;settings;set' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;settings;list' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;settings;unset' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;settings;help' { + [CompletionResult]::new('get', 'get', [CompletionResultType]::ParameterValue, 'Get a setting value') + [CompletionResult]::new('set', 'set', [CompletionResultType]::ParameterValue, 'Set a setting value') + [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'List all settings') + [CompletionResult]::new('unset', 'unset', [CompletionResultType]::ParameterValue, 'Unset a setting') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') + break + } + 'rsp;settings;help;get' { + break + } + 'rsp;settings;help;set' { + break + } + 'rsp;settings;help;list' { + break + } + 'rsp;settings;help;unset' { + break + } + 'rsp;settings;help;help' { + break + } + 'rsp;completions' { + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'rsp;help' { + [CompletionResult]::new('start-daemon', 'start-daemon', [CompletionResultType]::ParameterValue, 'Start the daemon') + [CompletionResult]::new('stop-daemon', 'stop-daemon', [CompletionResultType]::ParameterValue, 'Stop the daemon') + [CompletionResult]::new('restart', 'restart', [CompletionResultType]::ParameterValue, 'Restart the daemon (kill existing and start new)') + [CompletionResult]::new('play', 'play', [CompletionResultType]::ParameterValue, 'Play a track, album, or artist') + [CompletionResult]::new('pause', 'pause', [CompletionResultType]::ParameterValue, 'Pause playback') + [CompletionResult]::new('resume', 'resume', [CompletionResultType]::ParameterValue, 'Resume playback') + [CompletionResult]::new('toggle', 'toggle', [CompletionResultType]::ParameterValue, 'Toggle play/pause') + [CompletionResult]::new('stop', 'stop', [CompletionResultType]::ParameterValue, 'Stop playback') + [CompletionResult]::new('next', 'next', [CompletionResultType]::ParameterValue, 'Skip to next track') + [CompletionResult]::new('previous', 'previous', [CompletionResultType]::ParameterValue, 'Skip to previous track') + [CompletionResult]::new('volume', 'volume', [CompletionResultType]::ParameterValue, 'Set volume (0-100)') + [CompletionResult]::new('shuffle', 'shuffle', [CompletionResultType]::ParameterValue, 'Shuffle mode') + [CompletionResult]::new('queue', 'queue', [CompletionResultType]::ParameterValue, 'Queue management') + [CompletionResult]::new('status', 'status', [CompletionResultType]::ParameterValue, 'Show player status') + [CompletionResult]::new('scan', 'scan', [CompletionResultType]::ParameterValue, 'Scan music paths to populate database') + [CompletionResult]::new('settings', 'settings', [CompletionResultType]::ParameterValue, 'Settings management') + [CompletionResult]::new('completions', 'completions', [CompletionResultType]::ParameterValue, 'Generate shell completions (developer only)') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') + break + } + 'rsp;help;start-daemon' { + break + } + 'rsp;help;stop-daemon' { + break + } + 'rsp;help;restart' { + break + } + 'rsp;help;play' { + break + } + 'rsp;help;pause' { + break + } + 'rsp;help;resume' { + break + } + 'rsp;help;toggle' { + break + } + 'rsp;help;stop' { + break + } + 'rsp;help;next' { + break + } + 'rsp;help;previous' { + break + } + 'rsp;help;volume' { + break + } + 'rsp;help;shuffle' { + break + } + 'rsp;help;queue' { + break + } + 'rsp;help;status' { + break + } + 'rsp;help;scan' { + break + } + 'rsp;help;settings' { + [CompletionResult]::new('get', 'get', [CompletionResultType]::ParameterValue, 'Get a setting value') + [CompletionResult]::new('set', 'set', [CompletionResultType]::ParameterValue, 'Set a setting value') + [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'List all settings') + [CompletionResult]::new('unset', 'unset', [CompletionResultType]::ParameterValue, 'Unset a setting') + break + } + 'rsp;help;settings;get' { + break + } + 'rsp;help;settings;set' { + break + } + 'rsp;help;settings;list' { + break + } + 'rsp;help;settings;unset' { + break + } + 'rsp;help;completions' { + break + } + 'rsp;help;help' { + break + } + }) + + $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | + Sort-Object -Property ListItemText +} diff --git a/completions/rsp.zsh b/completions/rsp.zsh index d635e3c..e8da3d7 100644 --- a/completions/rsp.zsh +++ b/completions/rsp.zsh @@ -26,13 +26,13 @@ _rsp() { (( CURRENT += 1 )) curcontext="${curcontext%:*:*}:rsp-command-$line[1]:" case $line[1] in - (start) + (start-daemon) _arguments "${_arguments_options[@]}" : \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 ;; -(stop) +(stop-daemon) _arguments "${_arguments_options[@]}" : \ '-h[Print help]' \ '--help[Print help]' \ @@ -46,17 +46,13 @@ _arguments "${_arguments_options[@]}" : \ ;; (play) _arguments "${_arguments_options[@]}" : \ -'-i[Play immediately (add after current and skip to it)]' \ -'--now[Play immediately (add after current and skip to it)]' \ +'-i[Add after current track and skip to it]' \ +'--now[Add after current track and skip to it]' \ '-n[Add to queue after current track (don'\''t skip)]' \ '--next[Add to queue after current track (don'\''t skip)]' \ -'-l[Add to end of queue (default)]' \ -'--last[Add to end of queue (default)]' \ -'-L[List available artists/albums]' \ -'--list[List available artists/albums]' \ '-h[Print help]' \ '--help[Print help]' \ -'::query -- Artist/Album or local file path:_rsp_play_artist_album_completion' \ +'::query:_default' \ && ret=0 ;; (pause) @@ -77,7 +73,7 @@ _arguments "${_arguments_options[@]}" : \ '--help[Print help]' \ && ret=0 ;; -(stop-playback) +(stop) _arguments "${_arguments_options[@]}" : \ '-h[Print help]' \ '--help[Print help]' \ @@ -215,9 +211,9 @@ esac ;; (completions) _arguments "${_arguments_options[@]}" : \ -'--shell=[Also print to stdout for a specific shell]:SHELL:(bash elvish fish powershell zsh)' \ '-h[Print help]' \ '--help[Print help]' \ +'::shell -- Shell to generate (bash, zsh, fish, elvish, powershell) If not specified, generates all completion files:_default' \ && ret=0 ;; (help) @@ -232,11 +228,11 @@ _arguments "${_arguments_options[@]}" : \ (( CURRENT += 1 )) curcontext="${curcontext%:*:*}:rsp-help-command-$line[1]:" case $line[1] in - (start) + (start-daemon) _arguments "${_arguments_options[@]}" : \ && ret=0 ;; -(stop) +(stop-daemon) _arguments "${_arguments_options[@]}" : \ && ret=0 ;; @@ -260,7 +256,7 @@ _arguments "${_arguments_options[@]}" : \ _arguments "${_arguments_options[@]}" : \ && ret=0 ;; -(stop-playback) +(stop) _arguments "${_arguments_options[@]}" : \ && ret=0 ;; @@ -344,14 +340,14 @@ esac (( $+functions[_rsp_commands] )) || _rsp_commands() { local commands; commands=( -'start:Start the daemon' \ -'stop:Stop the daemon' \ +'start-daemon:Start the daemon' \ +'stop-daemon:Stop the daemon' \ 'restart:Restart the daemon (kill existing and start new)' \ 'play:Play a track, album, or artist' \ 'pause:Pause playback' \ 'resume:Resume playback' \ 'toggle:Toggle play/pause' \ -'stop-playback:Stop playback' \ +'stop:Stop playback' \ 'next:Skip to next track' \ 'previous:Skip to previous track' \ 'volume:Set volume (0-100)' \ @@ -360,7 +356,7 @@ _rsp_commands() { 'status:Show player status' \ 'scan:Scan music paths to populate database' \ 'settings:Settings management' \ -'completions:Generate shell completions and write to completions/ directory (bash, elvish, fish, powershell, zsh)' \ +'completions:Generate shell completions (developer only)' \ 'help:Print this message or the help of the given subcommand(s)' \ ) _describe -t commands 'rsp commands' commands "$@" @@ -373,14 +369,14 @@ _rsp__subcmd__completions_commands() { (( $+functions[_rsp__subcmd__help_commands] )) || _rsp__subcmd__help_commands() { local commands; commands=( -'start:Start the daemon' \ -'stop:Stop the daemon' \ +'start-daemon:Start the daemon' \ +'stop-daemon:Stop the daemon' \ 'restart:Restart the daemon (kill existing and start new)' \ 'play:Play a track, album, or artist' \ 'pause:Pause playback' \ 'resume:Resume playback' \ 'toggle:Toggle play/pause' \ -'stop-playback:Stop playback' \ +'stop:Stop playback' \ 'next:Skip to next track' \ 'previous:Skip to previous track' \ 'volume:Set volume (0-100)' \ @@ -389,7 +385,7 @@ _rsp__subcmd__help_commands() { 'status:Show player status' \ 'scan:Scan music paths to populate database' \ 'settings:Settings management' \ -'completions:Generate shell completions and write to completions/ directory (bash, elvish, fish, powershell, zsh)' \ +'completions:Generate shell completions (developer only)' \ 'help:Print this message or the help of the given subcommand(s)' \ ) _describe -t commands 'rsp help commands' commands "$@" @@ -479,10 +475,10 @@ _rsp__subcmd__help__subcmd__shuffle_commands() { local commands; commands=() _describe -t commands 'rsp help shuffle commands' commands "$@" } -(( $+functions[_rsp__subcmd__help__subcmd__start_commands] )) || -_rsp__subcmd__help__subcmd__start_commands() { +(( $+functions[_rsp__subcmd__help__subcmd__start-daemon_commands] )) || +_rsp__subcmd__help__subcmd__start-daemon_commands() { local commands; commands=() - _describe -t commands 'rsp help start commands' commands "$@" + _describe -t commands 'rsp help start-daemon commands' commands "$@" } (( $+functions[_rsp__subcmd__help__subcmd__status_commands] )) || _rsp__subcmd__help__subcmd__status_commands() { @@ -494,10 +490,10 @@ _rsp__subcmd__help__subcmd__stop_commands() { local commands; commands=() _describe -t commands 'rsp help stop commands' commands "$@" } -(( $+functions[_rsp__subcmd__help__subcmd__stop-playback_commands] )) || -_rsp__subcmd__help__subcmd__stop-playback_commands() { +(( $+functions[_rsp__subcmd__help__subcmd__stop-daemon_commands] )) || +_rsp__subcmd__help__subcmd__stop-daemon_commands() { local commands; commands=() - _describe -t commands 'rsp help stop-playback commands' commands "$@" + _describe -t commands 'rsp help stop-daemon commands' commands "$@" } (( $+functions[_rsp__subcmd__help__subcmd__toggle_commands] )) || _rsp__subcmd__help__subcmd__toggle_commands() { @@ -621,10 +617,10 @@ _rsp__subcmd__shuffle_commands() { local commands; commands=() _describe -t commands 'rsp shuffle commands' commands "$@" } -(( $+functions[_rsp__subcmd__start_commands] )) || -_rsp__subcmd__start_commands() { +(( $+functions[_rsp__subcmd__start-daemon_commands] )) || +_rsp__subcmd__start-daemon_commands() { local commands; commands=() - _describe -t commands 'rsp start commands' commands "$@" + _describe -t commands 'rsp start-daemon commands' commands "$@" } (( $+functions[_rsp__subcmd__status_commands] )) || _rsp__subcmd__status_commands() { @@ -636,10 +632,10 @@ _rsp__subcmd__stop_commands() { local commands; commands=() _describe -t commands 'rsp stop commands' commands "$@" } -(( $+functions[_rsp__subcmd__stop-playback_commands] )) || -_rsp__subcmd__stop-playback_commands() { +(( $+functions[_rsp__subcmd__stop-daemon_commands] )) || +_rsp__subcmd__stop-daemon_commands() { local commands; commands=() - _describe -t commands 'rsp stop-playback commands' commands "$@" + _describe -t commands 'rsp stop-daemon commands' commands "$@" } (( $+functions[_rsp__subcmd__toggle_commands] )) || _rsp__subcmd__toggle_commands() { @@ -657,9 +653,3 @@ if [ "$funcstack[1]" = "_rsp" ]; then else compdef _rsp rsp fi - -_rsp_play_artist_album_completion() { - local -a artists - artists=("$(rsp play --list 2>/dev/null)") - _describe -t artist-album 'artist/album' artists -} diff --git a/install.sh b/install.sh index 5a1e888..a7317e9 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ cargo build --release echo "Stopping existing daemon..." systemctl --user stop rsplayer 2>/dev/null || true -rsp stop 2>/dev/null || true +rsp stop-daemon 2>/dev/null || true echo "Installing to /usr/bin/rsp..." sudo cp target/release/rsp /usr/bin/rsp @@ -26,4 +26,40 @@ else fi echo "" -echo "Done! Run 'rsp start' to start the daemon." +echo "Installing shell completions..." +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +shell_name=$(basename "${SHELL:-}") +case "$shell_name" in + bash) + dest="${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions" + mkdir -p "$dest" + cp "$SCRIPT_DIR/completions/rsp.bash" "$dest/rsp" + echo " → Bash completions: $dest/rsp" + ;; + zsh) + dest="/usr/share/zsh/site-functions/_rsp" + sudo cp "$SCRIPT_DIR/completions/rsp.zsh" "$dest" + echo " → Zsh completions: $dest" + ;; + fish) + dest="$HOME/.config/fish/completions/rsp.fish" + mkdir -p "$(dirname "$dest")" + cp "$SCRIPT_DIR/completions/rsp.fish" "$dest" + echo " → Fish completions: $dest" + ;; + elvish) + dest="$HOME/.config/elvish/rc.d/rsp.elvish" + mkdir -p "$(dirname "$dest")" + cp "$SCRIPT_DIR/completions/rsp.elvish" "$dest" + echo " → Elvish completions: $dest" + ;; + powershell) + echo " → PowerShell: source \"$SCRIPT_DIR/completions/rsp.powershell\" from your profile" + ;; + *) + echo " → Unrecognized shell '$shell_name'; completion files are in $SCRIPT_DIR/completions/" + ;; +esac + +echo "" +echo "Done! Run 'rsp start-daemon' to start the daemon." diff --git a/src/cli.rs b/src/cli.rs index e0cea63..7d56de6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,7 @@ use crate::config::Config; use crate::database::Database; -use clap::{Parser, Subcommand}; +use clap::{CommandFactory, Parser, Subcommand}; +use clap_complete::{Shell, generate}; use std::path::PathBuf; #[derive(Parser)] @@ -73,6 +74,14 @@ pub enum Commands { #[command(subcommand)] command: SettingsCommands, }, + #[clap(hide = true)] + /// Generate shell completions (developer only) + Completions { + /// Shell to generate (bash, zsh, fish, elvish, powershell) + /// If not specified, generates all completion files + #[arg(value_name = "SHELL")] + shell: Option, + }, } #[derive(Subcommand)] @@ -200,6 +209,38 @@ impl Cli { } } } + Commands::Completions { shell } => { + let mut cmd = Cli::command(); + if let Some(s) = shell { + let shell = match s.as_str() { + "bash" => Shell::Bash, + "zsh" => Shell::Zsh, + "fish" => Shell::Fish, + "elvish" => Shell::Elvish, + "powershell" => Shell::PowerShell, + _ => { + eprintln!("Unknown shell: {s}"); + return Ok(()); + } + }; + generate(shell, &mut cmd, "rsp", &mut std::io::stdout()); + } else { + std::fs::create_dir_all("completions/")?; + let shells = [ + (Shell::Bash, "bash"), + (Shell::Zsh, "zsh"), + (Shell::Fish, "fish"), + (Shell::Elvish, "elvish"), + (Shell::PowerShell, "powershell"), + ]; + for (shell, ext) in &shells { + let path = format!("completions/rsp.{ext}"); + let mut file = std::fs::File::create(&path)?; + generate(*shell, &mut cmd, "rsp", &mut file); + println!("Generated {path}"); + } + } + } } Ok(()) } -- cgit v1.2.3