2020-01-15 01:20:38 -08:00
#compdef just
autoload -U is-at-least
_just( ) {
typeset -A opt_args
typeset -a _arguments_options
local ret = 1
if is-at-least 5.2; then
_arguments_options = ( -s -S -C)
else
_arguments_options = ( -s -C)
fi
local context curcontext = " $curcontext " state line
2020-03-16 17:20:14 -07:00
local common = (
2020-09-17 19:43:04 -07:00
'--chooser=[Override binary invoked by `--choose`]' \
2020-01-15 01:20:38 -08:00
'--color=[Print colorful output]: :(auto always never)' \
2021-02-09 01:00:04 -08:00
'--list-heading=[Print <TEXT> before list]' \
'--list-prefix=[Print <TEXT> before each list item]' \
'-f+[Use <JUSTFILE> as justfile]' \
'--justfile=[Use <JUSTFILE> as justfile]' \
2020-03-16 17:20:14 -07:00
'*--set[Override <VARIABLE> with <VALUE>]: :_just_variables' \
2020-01-15 01:20:38 -08:00
'--shell=[Invoke <SHELL> to run recipes]' \
'*--shell-arg=[Invoke shell with <SHELL-ARG> as an argument]' \
'-d+[Use <WORKING-DIRECTORY> as working directory. --justfile must also be set]' \
'--working-directory=[Use <WORKING-DIRECTORY> as working directory. --justfile must also be set]' \
2021-05-09 20:35:35 -07:00
'-c+[Run an arbitrary command with the working directory, `.env`, overrides, and exports set]' \
'--command=[Run an arbitrary command with the working directory, `.env`, overrides, and exports set]' \
2020-01-15 01:20:38 -08:00
'--completions=[Print shell completion script for <SHELL>]: :(zsh bash fish powershell elvish)' \
2020-03-16 17:20:14 -07:00
'-s+[Show information about <RECIPE>]: :_just_commands' \
'--show=[Show information about <RECIPE>]: :_just_commands' \
2020-01-15 01:20:38 -08:00
'(-q --quiet)--dry-run[Print what just would do without doing it]' \
'--highlight[Highlight echoed recipe lines in bold]' \
2020-05-23 20:41:12 -07:00
'--no-dotenv[Don' \' 't load `.env` file]' \
2020-01-15 01:20:38 -08:00
'--no-highlight[Don' \' 't highlight echoed recipe lines in bold]' \
'(--dry-run)-q[Suppress all output]' \
'(--dry-run)--quiet[Suppress all output]' \
2021-05-09 20:35:35 -07:00
'--shell-command[Invoke <COMMAND> with the shell used to run recipe lines and backticks]' \
2020-01-15 01:20:38 -08:00
'--clear-shell-args[Clear shell arguments]' \
2020-08-21 15:13:54 -07:00
'-u[Return list and summary entries in source order]' \
'--unsorted[Return list and summary entries in source order]' \
2021-06-12 15:34:41 -07:00
'--unstable[Enable unstable features]' \
2020-01-15 01:20:38 -08:00
'*-v[Use verbose output]' \
'*--verbose[Use verbose output]' \
2021-07-31 13:53:27 -07:00
'--changelog[Print changelog]' \
2020-10-10 17:54:58 -07:00
'--choose[Select one or more recipes to run using a binary. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`]' \
2020-01-15 01:20:38 -08:00
'--dump[Print entire justfile]' \
'-e[Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`]' \
'--edit[Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`]' \
2021-04-25 17:25:34 -07:00
'--evaluate[Evaluate and print all variables. If a variable name is given as an argument, only print that variable' \' 's value.]' \
2021-06-08 01:01:27 -07:00
'--fmt[Format and overwrite justfile]' \
2020-01-15 01:20:38 -08:00
'--init[Initialize new justfile in project root]' \
'-l[List available recipes and their arguments]' \
'--list[List available recipes and their arguments]' \
'--summary[List names of available recipes]' \
2020-03-13 22:19:43 -07:00
'--variables[List names of variables]' \
2020-01-15 01:20:38 -08:00
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
2020-03-16 17:20:14 -07:00
)
_arguments " ${ _arguments_options [@] } " $common \
'1: :_just_commands' \
'*: :->args' \
&& ret = 0
case $state in
args)
curcontext = " ${ curcontext % : * } - ${ words [2] } : "
local lastarg = ${ words [ ${# words } ] }
2020-10-17 21:58:44 -07:00
local recipe
2020-03-16 17:20:14 -07:00
2020-10-17 21:58:44 -07:00
local cmds; cmds = (
${ (s : : ) $( _call_program commands just --summary) }
)
# Find first recipe name
for ( ( i = 2; i < $# words; i++ ) ) do
if [ [ ${ cmds [(I) ${ words [i] } ] } -gt 0 ] ] ; then
recipe = ${ words [i] }
break
fi
done
if [ [ $lastarg = */* ] ] ; then
2020-03-16 17:20:14 -07:00
# Arguments contain slash would be recognised as a file
_arguments -s -S $common '*:: :_files'
2020-10-17 21:58:44 -07:00
elif [ [ $lastarg = *= * ] ] ; then
# Arguments contain equal would be recognised as a variable
_message "value"
elif [ [ $recipe ] ] ; then
2020-03-16 17:20:14 -07:00
# Show usage message
2020-10-17 21:58:44 -07:00
_message " `just --show $recipe ` "
2020-03-16 17:20:14 -07:00
# Or complete with other commands
#_arguments -s -S $common '*:: :_just_commands'
2020-10-17 21:58:44 -07:00
else
_arguments -s -S $common '*:: :_just_commands'
2020-03-16 17:20:14 -07:00
fi
; ;
esac
return ret
2020-01-15 01:20:38 -08:00
}
( ( $+functions[ _just_commands] ) ) ||
_just_commands( ) {
2020-10-17 21:58:44 -07:00
[ [ $PREFIX = -* ] ] && return 1
integer ret = 1
local variables; variables = (
${ (s : : ) $( _call_program commands just --variables) }
)
2020-01-15 01:20:38 -08:00
local commands; commands = (
2020-03-16 17:20:14 -07:00
${ ${ ${ (M) " ${ (f) $( _call_program commands just --list) } " : # * } / ##/ } / ##/ : Args : }
2020-01-15 01:20:38 -08:00
)
2020-03-16 17:20:14 -07:00
2020-10-17 21:58:44 -07:00
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
2020-01-15 01:20:38 -08:00
}
2020-03-16 17:20:14 -07:00
( ( $+functions[ _just_variables] ) ) ||
_just_variables( ) {
2020-10-17 21:58:44 -07:00
[ [ $PREFIX = -* ] ] && return 1
integer ret = 1
2020-03-16 17:20:14 -07:00
local variables; variables = (
${ (s : : ) $( _call_program commands just --variables) }
)
2020-10-17 21:58:44 -07:00
if compset -P '*=' ; then
case " ${ ${ words [-1]%=* } #*= } " in
*) _message 'value' && ret = 0 ; ;
esac
else
_describe -t variables 'variables' variables && ret = 0
fi
return ret
2020-03-16 17:20:14 -07:00
}
2020-03-14 21:41:57 -07:00
_just " $@ "