Add support for global justfile completions#3022
Open
spkane wants to merge 5 commits intocasey:masterfrom
Open
Add support for global justfile completions#3022spkane wants to merge 5 commits intocasey:masterfrom
spkane wants to merge 5 commits intocasey:masterfrom
Conversation
Author
|
Fixes: #2394 |
Author
|
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
Author
|
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.