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 | |
| parent | limit completions to LIMIT (diff) | |
| download | rsplayer-4ac442d6fbd440a86b0179c0c8e4237115424d56.tar.gz rsplayer-4ac442d6fbd440a86b0179c0c8e4237115424d56.zip | |
improved ZSH autocompletion script
| -rw-r--r-- | .zed/tasks.json | 4 | ||||
| -rw-r--r-- | completions/_rsp | 14 |
2 files changed, 13 insertions, 5 deletions
diff --git a/.zed/tasks.json b/.zed/tasks.json index 70f3bfe..3acc441 100644 --- a/.zed/tasks.json +++ b/.zed/tasks.json | |||
| @@ -15,14 +15,14 @@ | |||
| 15 | }, | 15 | }, |
| 16 | { | 16 | { |
| 17 | "label": "install", | 17 | "label": "install", |
| 18 | "command": "./install.sh && ls -lha $ZED_WORKTREE_ROOT/target/release/rsp | awk '{print $5}'", | 18 | "command": "./install.sh && ls -lha $ZED_WORKTREE_ROOT/target/release/rsp | awk '{print $2}'", |
| 19 | "show_command": false, | 19 | "show_command": false, |
| 20 | "show_summary": false, | 20 | "show_summary": false, |
| 21 | "save": "all", | 21 | "save": "all", |
| 22 | }, | 22 | }, |
| 23 | { | 23 | { |
| 24 | "label": "build release", | 24 | "label": "build release", |
| 25 | "command": "cargo b -r && ls -lha $ZED_WORKTREE_ROOT/target/release/rsp | awk '{print $5}'", | 25 | "command": "cargo b -r && ls -l $ZED_WORKTREE_ROOT/target/release/rsp | awk '{print $2}'", |
| 26 | "show_command": false, | 26 | "show_command": false, |
| 27 | "show_summary": false, | 27 | "show_summary": false, |
| 28 | "save": "all", | 28 | "save": "all", |
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[@]}" |
