diff options
| author | salmonik <raisersoft@proton.me> | 2026-06-12 13:32:40 +0300 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-06-12 13:32:40 +0300 |
| commit | 4ac442d6fbd440a86b0179c0c8e4237115424d56 (patch) | |
| tree | fbe5687b23697a335c0cc129d658b394d93c9271 /completions | |
| parent | limit completions to LIMIT (diff) | |
| download | rsplayer-4ac442d6fbd440a86b0179c0c8e4237115424d56.tar.gz rsplayer-4ac442d6fbd440a86b0179c0c8e4237115424d56.zip | |
improved ZSH autocompletion script
Diffstat (limited to 'completions')
| -rw-r--r-- | completions/_rsp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/completions/_rsp b/completions/_rsp index 9bf0579..89d122b 100644 --- a/completions/_rsp +++ b/completions/_rsp | |||
| @@ -2,9 +2,17 @@ | |||
| 2 | functions[_rsp_clap]=$functions[_rsp] | 2 | functions[_rsp_clap]=$functions[_rsp] |
| 3 | 3 | ||
| 4 | _rsp() { | 4 | _rsp() { |
| 5 | setopt nobanghist | ||
| 5 | case $words[2] in | 6 | case $words[2] in |
| 6 | play|queue) | 7 | play|queue) |
| 7 | if (( CURRENT > 2 )); then | 8 | if (( CURRENT > 2 )); then |
| 9 | local cur="${words[$CURRENT]}" | ||
| 10 | if [[ "$words[2]" == "play" && "$cur" == -* ]]; then | ||
| 11 | local -a flags | ||
| 12 | flags=('-i' '--now' '-n' '--next' '-a' '--album') | ||
| 13 | _describe 'flags' flags | ||
| 14 | return 0 | ||
| 15 | fi | ||
| 8 | _rsp_complete_args | 16 | _rsp_complete_args |
| 9 | return 0 | 17 | return 0 |
| 10 | fi | 18 | fi |
| @@ -14,14 +22,14 @@ _rsp() { | |||
| 14 | } | 22 | } |
| 15 | 23 | ||
| 16 | _rsp_complete_args() { | 24 | _rsp_complete_args() { |
| 17 | setopt localoptions | ||
| 18 | setopt nobanghist | 25 | setopt nobanghist |
| 19 | local -a args=("${(@)words[3,$CURRENT]}") | 26 | local -a args=("${(@)words[3,$CURRENT]}") |
| 20 | local cur="${(j: :)args}" | 27 | local cur="${(j: :)args}" |
| 28 | # No completion if this is a flag (handled above) | ||
| 29 | [[ "$words[2]" == "play" && "$cur" == -* ]] && return 1 | ||
| 21 | local cur_clean="${cur//\\/}" | 30 | local cur_clean="${cur//\\/}" |
| 22 | local -a suggestions | 31 | local -a suggestions |
| 23 | suggestions=("${(@f)"$(rsp db-complete "$cur" 2>/dev/null)"}") | 32 | suggestions=("${(@f)"$(rsp db-complete "$cur" 2>/dev/null)"}") |
| 24 | # Filter out empty entries (e.g. from empty command output) | ||
| 25 | local -a filtered=() | 33 | local -a filtered=() |
| 26 | for s in "${suggestions[@]}"; do | 34 | for s in "${suggestions[@]}"; do |
| 27 | if [[ -n "$s" ]]; then | 35 | if [[ -n "$s" ]]; then |
| @@ -49,7 +57,7 @@ _rsp_complete_args() { | |||
| 49 | fi | 57 | fi |
| 50 | done | 58 | done |
| 51 | if (( ${#suggestions} > 1 )); then | 59 | if (( ${#suggestions} > 1 )); then |
| 52 | compstate[insert]=menu | 60 | compstate[insert]= |
| 53 | fi | 61 | fi |
| 54 | if [[ ${vals[1]} == */ ]]; then | 62 | if [[ ${vals[1]} == */ ]]; then |
| 55 | compadd -U -S '' -M 'm:{a-z}={A-Z} l:|=*' -d display -- "${vals[@]}" | 63 | compadd -U -S '' -M 'm:{a-z}={A-Z} l:|=*' -d display -- "${vals[@]}" |
