Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions completions/just.bash
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,20 @@ _just() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
else
local recipes=$(just --summary 2> /dev/null)
# Check if --global-justfile or -g flag is present
local use_global=""
for word in "${words[@]}"; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done

local recipes=$(just $use_global --summary 2> /dev/null)

if echo "${cur}" | \grep -qF '/'; then
local path_prefix=$(echo "${cur}" | sed 's/[/][^/]*$/\//')
local recipes=$(just --summary 2> /dev/null -- "${path_prefix}")
local recipes=$(just $use_global --summary 2> /dev/null -- "${path_prefix}")
local recipes=$(printf "${path_prefix}%s\t" $recipes)
fi

Expand Down
23 changes: 23 additions & 0 deletions completions/just.elvish
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ set edit:completion:arg-completer[just] = {|@words|
fn cand {|text desc|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
}

# Check if --global-justfile or -g flag is present
var use-global = []
for word $words[1..-1] {
if (or (eq $word '-g') (eq $word '--global-justfile')) {
set use-global = ['--global-justfile']
break
}
}

var command = 'just'
for word $words[1..-1] {
if (str:has-prefix $word '-') {
Expand Down Expand Up @@ -90,4 +100,17 @@ set edit:completion:arg-completer[just] = {|@words|
}
]
$completions[$command]

# Complete recipes if not completing an option
var current = $words[-1]
if (not (str:has-prefix $current '-')) {
try {
var recipes = [(just $@use-global --summary 2>/dev/null | str:split ' ')]
for recipe $recipes {
if (not (eq $recipe '')) {
cand $recipe ''
}
}
} catch { }
}
}
12 changes: 10 additions & 2 deletions completions/just.fish
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
function __fish_just_complete_recipes
if string match -rq '(-f|--justfile)\s*=?(?<justfile>[^\s]+)' -- (string split -- ' -- ' (commandline -pc))[1]
set -l cmdline (string split -- ' -- ' (commandline -pc))[1]
if string match -rq '(-f|--justfile)\s*=?(?<justfile>[^\s]+)' -- $cmdline
set -fx JUST_JUSTFILE "$justfile"
end
printf "%s\n" (string split " " (just --summary))

# Check if --global-justfile or -g flag is present
set -l use_global
if string match -rq '(^|\s)(-g|--global-justfile)(\s|$)' -- $cmdline
set use_global --global-justfile
end

printf "%s\n" (string split " " (just $use_global --summary))
end

# don't suggest files right off
Expand Down
10 changes: 8 additions & 2 deletions completions/just.nu
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
def "nu-complete just" [] {
(^just --dump --unstable --dump-format json | from json).recipes | transpose recipe data | flatten | where {|row| $row.private == false } | select recipe doc parameters | rename value description
def "nu-complete just" [context: string] {
# Check if --global-justfile or -g flag is present
let use_global = if ($context | str contains " -g ") or ($context | str contains " --global-justfile ") or ($context | str ends-with " -g") or ($context | str ends-with " --global-justfile") {
["--global-justfile"]
} else {
[]
}
(^just ...$use_global --dump --unstable --dump-format json | from json).recipes | transpose recipe data | flatten | where {|row| $row.private == false } | select recipe doc parameters | rename value description
}

# Just: A Command Runner
Expand Down
6 changes: 5 additions & 1 deletion completions/just.powershell
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {

$justArgs = @("--summary")

if (Test-Path $justFileLocation) {
# Check if --global-justfile or -g flag is present
if ($commandElements -contains "-g" -or $commandElements -contains "--global-justfile") {
$justArgs += @("--global-justfile")
}
elseif (Test-Path $justFileLocation) {
$justArgs += @("--justfile", $justFileLocation)
}

Expand Down
57 changes: 40 additions & 17 deletions completions/just.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand Down Expand Up @@ -99,8 +100,17 @@ _just() {
local lastarg=${words[${#words}]}
local recipe

# Check if --global-justfile or -g flag is present
local use_global=""
for word in "${words[@]}"; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done

local cmds; cmds=(
${(s: :)$(_call_program commands just --summary)}
${(s: :)$(_call_program commands just $use_global --summary)}
)

# Find first recipe name
Expand All @@ -119,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
Expand All @@ -136,31 +146,44 @@ _just() {
_just_commands() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local variables; variables=(
${(s: :)$(_call_program commands just --variables)}
)
local commands; commands=(
${${${(M)"${(f)$(_call_program commands just --list)}":# *}/ ##/}/ ##/:Args: }
)

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
# Check if --global-justfile or -g flag is present
local use_global=""
for word in "${words[@]}"; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done

# Get recipes from --summary (includes full module::recipe paths)
local summary_output=$(_call_program commands just $use_global --summary)

# 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
(( $+functions[_just_variables] )) ||
_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
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done
local variables; variables=(
${(s: :)$(_call_program commands just --variables)}
${(s: :)$(_call_program commands just $use_global --variables)}
)

if compset -P '*='; then
Expand Down
117 changes: 108 additions & 9 deletions src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ mod tests {
replace(&mut script, needle, replacement);
}
}
clap_complete::Shell::Elvish => {
for (needle, replacement) in ELVISH_COMPLETION_REPLACEMENTS {
replace(&mut script, needle, replacement);
}
}
clap_complete::Shell::Fish => {
script.insert_str(0, FISH_RECIPE_COMPLETIONS);
}
Expand All @@ -101,10 +106,18 @@ mod tests {
}

const FISH_RECIPE_COMPLETIONS: &str = r#"function __fish_just_complete_recipes
if string match -rq '(-f|--justfile)\s*=?(?<justfile>[^\s]+)' -- (string split -- ' -- ' (commandline -pc))[1]
set -l cmdline (string split -- ' -- ' (commandline -pc))[1]
if string match -rq '(-f|--justfile)\s*=?(?<justfile>[^\s]+)' -- $cmdline
set -fx JUST_JUSTFILE "$justfile"
end
printf "%s\n" (string split " " (just --summary))

# Check if --global-justfile or -g flag is present
set -l use_global
if string match -rq '(^|\s)(-g|--global-justfile)(\s|$)' -- $cmdline
set use_global --global-justfile
end

printf "%s\n" (string split " " (just $use_global --summary))
end

# don't suggest files right off
Expand All @@ -116,6 +129,50 @@ complete -c just -a '(__fish_just_complete_recipes)'
# autogenerated completions
"#;

const ELVISH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
(
r#" fn cand {|text desc|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
}
var command = 'just'"#,
r#" fn cand {|text desc|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
}

# Check if --global-justfile or -g flag is present
var use-global = []
for word $words[1..-1] {
if (or (eq $word '-g') (eq $word '--global-justfile')) {
set use-global = ['--global-justfile']
break
}
}

var command = 'just'"#,
),
(
r#" ]
$completions[$command]
}"#,
r#" ]
$completions[$command]

# Complete recipes if not completing an option
var current = $words[-1]
if (not (str:has-prefix $current '-')) {
try {
var recipes = [(just $@use-global --summary 2>/dev/null | str:split ' ')]
for recipe $recipes {
if (not (eq $recipe '')) {
cand $recipe ''
}
}
} catch { }
}
}"#,
),
];

const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
(
r#" _arguments "${_arguments_options[@]}" : \"#,
Expand Down Expand Up @@ -149,8 +206,17 @@ complete -c just -a '(__fish_just_complete_recipes)'
local lastarg=${words[${#words}]}
local recipe

# Check if --global-justfile or -g flag is present
local use_global=""
for word in ${words[@]}; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done

local cmds; cmds=(
${(s: :)$(_call_program commands just --summary)}
${(s: :)$(_call_program commands just $use_global --summary)}
)

# Find first recipe name
Expand Down Expand Up @@ -185,11 +251,21 @@ complete -c just -a '(__fish_just_complete_recipes)'
" local commands; commands=()",
r#" [[ $PREFIX = -* ]] && return 1
integer ret=1

# Check if --global-justfile or -g flag is present
local use_global=""
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 --variables)}
${(s: :)$(_call_program commands just $use_global --variables)}
)
local commands; commands=(
${${${(M)"${(f)$(_call_program commands just --list)}":# *}/ ##/}/ ##/:Args: }
${${${(M)"${(f)$(_call_program commands just $use_global --list)}":# *}/ ##/}/ ##/:Args: }
)
"#,
),
Expand All @@ -211,8 +287,18 @@ complete -c just -a '(__fish_just_complete_recipes)'
_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
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done

local variables; variables=(
${(s: :)$(_call_program commands just --variables)}
${(s: :)$(_call_program commands just $use_global --variables)}
)

if compset -P '*='; then
Expand Down Expand Up @@ -242,7 +328,11 @@ _just "$@""#,

$justArgs = @("--summary")

if (Test-Path $justFileLocation) {
# Check if --global-justfile or -g flag is present
if ($commandElements -contains "-g" -or $commandElements -contains "--global-justfile") {
$justArgs += @("--global-justfile")
}
elseif (Test-Path $justFileLocation) {
$justArgs += @("--justfile", $justFileLocation)
}

Expand All @@ -267,11 +357,20 @@ _just "$@""#,
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
elif [[ ${COMP_CWORD} -eq 1 ]]; then
local recipes=$(just --summary 2> /dev/null)
# Check if --global-justfile or -g flag is present
local use_global=""
for word in "${words[@]}"; do
if [[ "$word" == "-g" || "$word" == "--global-justfile" ]]; then
use_global="--global-justfile"
break
fi
done

local recipes=$(just $use_global --summary 2> /dev/null)

if echo "${cur}" | \grep -qF '/'; then
local path_prefix=$(echo "${cur}" | sed 's/[/][^/]*$/\//')
local recipes=$(just --summary 2> /dev/null -- "${path_prefix}")
local recipes=$(just $use_global --summary 2> /dev/null -- "${path_prefix}")
local recipes=$(printf "${path_prefix}%s\t" $recipes)
fi

Expand Down