Add support for global justfile completions#3022
Add support for global justfile completions#3022spkane wants to merge 5 commits intocasey:masterfrom
Conversation
|
Fixes: #2394 |
|
This is the diff, which worked on my machine (running zsh 5.9 (x86_64-pc-linux-gnu) just 1.46.0 on Linux 6.12.63-1-lts), using your diff --git a/completions/just.zsh b/completions/just.zsh
index a69f7c4d..69e40ef4 100644
--- a/completions/just.zsh
+++ b/completions/just.zsh
@@ -44,6 +44,7 @@ _just() {
'--request=[Execute <REQUEST>. For internal testing purposes only. May be changed or removed at any time.]: :_default' \
'-s+[Show recipe at <PATH>]: :(_just_commands)' \
'--show=[Show recipe at <PATH>]: :(_just_commands)' \
+'()--usage=[Print recipe usage information]:PATH:_default' \
'--check[Run \`--fmt\` in '\''check'\'' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required.]' \
'--clear-shell-args[Clear shell arguments]' \
'(-q --quiet)-n[Print what just would do without doing it]' \
@@ -101,7 +102,7 @@ _just() {
# Check if --global-justfile or -g flag is present
local use_global=""
- for word in ${words[@]}; do
+ for word in "${words[@]}"; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
@@ -128,7 +129,7 @@ _just() {
_message "value"
elif [[ $recipe ]]; then
# Show usage message
- _message "`just --show $recipe`"
+ _message "`just $use_global --show $recipe`"
# Or complete with other commands
#_arguments -s -S $common '*:: :_just_commands'
else
@@ -148,29 +149,24 @@ _just_commands() {
# Check if --global-justfile or -g flag is present
local use_global=""
- for word in ${words[@]}; do
+ for word in "${words[@]}"; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done
- local variables; variables=(
- ${(s: :)$(_call_program commands just $use_global --variables)}
- )
- local commands; commands=(
- ${${${(M)"${(f)$(_call_program commands just $use_global --list)}":# *}/ ##/}/ ##/:Args: }
- )
+ # Get recipes from --summary (includes full module::recipe paths)
+ local summary_output=$(_call_program commands just $use_global --summary)
- if compset -P '*='; then
- case "${${words[-1]%=*}#*=}" in
- *) _message 'value' && ret=0 ;;
- esac
- else
- _describe -t variables 'variables' variables -qS "=" && ret=0
- _describe -t commands 'just commands' commands "$@"
- fi
+ # Split into array properly
+ local -a recipes
+ recipes=("${(@s: :)summary_output}")
+ # Add recipes directly to completion
+ compadd -a recipes
+
+ return 0
}
if [ "$funcstack[1]" = "_just" ]; then
@@ -178,16 +174,14 @@ if [ "$funcstack[1]" = "_just" ]; then
_just_variables() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
-
# Check if --global-justfile or -g flag is present
local use_global=""
- for word in ${words[@]}; do
+ for word in "${words[@]}"; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done
-
local variables; variables=(
${(s: :)$(_call_program commands just $use_global --variables)}
) |
With the help of ClaudeAI (and lots of patience) Now `just -g <TAB>` is working as expected including for modules, so one can run `just -g mod<TAB>` and it will be autocompleted to `just -g module::` and you can then `just -g module::<TAB>` to see all the available recipes.
Fix ZSH autocommpletions
|
@casey It is likely this PR needs some confirmation for the non-bash/ZSH shells, but is there anything I can do to help get this merged as it would be really helpful. |
|
I switched to using Clap's dynamic completion engine in #3167. The new completion engine calls into the I created #2406 to track improvements to the new completion engine in one place. The new completions attempt to respect command line flags as much as possible, so this should work. |
I have only tested the Bash version of this change, but I used Claude Code to update the rest of them to match the general logic.