1#compdef just
2
3autoload -U is-at-least
4
5_just() {
6 typeset -A opt_args
7 typeset -a _arguments_options
8 local ret=1
9
10 if is-at-least 5.2; then
11 _arguments_options=(-s -S -C)
12 else
13 _arguments_options=(-s -C)
14 fi
15
16 local context curcontext="$curcontext" state line
17 local common=(
18'--chooser=[Override binary invoked by `--choose`]' \
19'--color=[Print colorful output]: :(auto always never)' \
20'--dump-format=[Dump justfile as <FORMAT>]: :(just json)' \
21'--list-heading=[Print <TEXT> before list]' \
22'--list-prefix=[Print <TEXT> before each list item]' \
23'-f+[Use <JUSTFILE> as justfile]' \
24'--justfile=[Use <JUSTFILE> as justfile]' \
25'*--set[Override <VARIABLE> with <VALUE>]: :_just_variables' \
26'--shell=[Invoke <SHELL> to run recipes]' \
27'*--shell-arg=[Invoke shell with <SHELL-ARG> as an argument]' \
28'-d+[Use <WORKING-DIRECTORY> as working directory. --justfile must also be set]' \
29'--working-directory=[Use <WORKING-DIRECTORY> as working directory. --justfile must also be set]' \
30'-c+[Run an arbitrary command with the working directory, `.env`, overrides, and exports set]' \
31'--command=[Run an arbitrary command with the working directory, `.env`, overrides, and exports set]' \
32'--completions=[Print shell completion script for <SHELL>]: :(zsh bash fish powershell elvish)' \
33'-s+[Show information about <RECIPE>]: :_just_commands' \
34'--show=[Show information about <RECIPE>]: :_just_commands' \
35'(--dotenv-path)--dotenv-filename=[Search for environment file named <DOTENV-FILENAME> instead of `.env`]' \
36'--dotenv-path=[Load environment file at <DOTENV-PATH> instead of searching for one]' \
37'--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.]' \
38'(-q --quiet)-n[Print what just would do without doing it]' \
39'(-q --quiet)--dry-run[Print what just would do without doing it]' \
40'--highlight[Highlight echoed recipe lines in bold]' \
41'--no-dotenv[Don'\''t load `.env` file]' \
42'--no-highlight[Don'\''t highlight echoed recipe lines in bold]' \
43'(-n --dry-run)-q[Suppress all output]' \
44'(-n --dry-run)--quiet[Suppress all output]' \
45'--shell-command[Invoke <COMMAND> with the shell used to run recipe lines and backticks]' \
46'--clear-shell-args[Clear shell arguments]' \
47'-u[Return list and summary entries in source order]' \
48'--unsorted[Return list and summary entries in source order]' \
49'--unstable[Enable unstable features]' \
50'*-v[Use verbose output]' \
51'*--verbose[Use verbose output]' \
52'--changelog[Print changelog]' \
53'--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`]' \
54'--dump[Print justfile]' \
55'-e[Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`]' \
56'--edit[Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`]' \
57'--evaluate[Evaluate and print all variables. If a variable name is given as an argument, only print that variable'\''s value.]' \
58'--fmt[Format and overwrite justfile]' \
59'--init[Initialize new justfile in project root]' \
60'-l[List available recipes and their arguments]' \
61'--list[List available recipes and their arguments]' \
62'--summary[List names of available recipes]' \
63'--variables[List names of variables]' \
64'-h[Print help information]' \
65'--help[Print help information]' \
66'-V[Print version information]' \
67'--version[Print version information]' \
68)
69
70 _arguments "${_arguments_options[@]}" $common \
71 '1: :_just_commands' \
72 '*: :->args' \
73 && ret=0
74
75 case $state in
76 args)
77 curcontext="${curcontext%:*}-${words[2]}:"
78
79 local lastarg=${words[${#words}]}
80 local recipe
81
82 local cmds; cmds=(
83 ${(s: :)$(_call_program commands just --summary)}
84 )
85
86 # Find first recipe name
87 for ((i = 2; i < $#words; i++ )) do
88 if [[ ${cmds[(I)${words[i]}]} -gt 0 ]]; then
89 recipe=${words[i]}
90 break
91 fi
92 done
93
94 if [[ $lastarg = */* ]]; then
95 # Arguments contain slash would be recognised as a file
96 _arguments -s -S $common '*:: :_files'
97 elif [[ $lastarg = *=* ]]; then
98 # Arguments contain equal would be recognised as a variable
99 _message "value"
100 elif [[ $recipe ]]; then
101 # Show usage message
102 _message "`just --show $recipe`"
103 # Or complete with other commands
104 #_arguments -s -S $common '*:: :_just_commands'
105 else
106 _arguments -s -S $common '*:: :_just_commands'
107 fi
108 ;;
109 esac
110
111 return ret
112}
113
114(( $+functions[_just_commands] )) ||
115_just_commands() {
116 [[ $PREFIX = -* ]] && return 1
117 integer ret=1
118 local variables; variables=(
119 ${(s: :)$(_call_program commands just --variables)}
120 )
121 local commands; commands=(
122 ${${${(M)"${(f)$(_call_program commands just --list)}":# *}/ ##/}/ ##/:Args: }
123 )
124
125 if compset -P '*='; then
126 case "${${words[-1]%=*}#*=}" in
127 *) _message 'value' && ret=0 ;;
128 esac
129 else
130 _describe -t variables 'variables' variables -qS "=" && ret=0
131 _describe -t commands 'just commands' commands "$@"
132 fi
133
134}
135
136(( $+functions[_just_variables] )) ||
137_just_variables() {
138 [[ $PREFIX = -* ]] && return 1
139 integer ret=1
140 local variables; variables=(
141 ${(s: :)$(_call_program commands just --variables)}
142 )
143
144 if compset -P '*='; then
145 case "${${words[-1]%=*}#*=}" in
146 *) _message 'value' && ret=0 ;;
147 esac
148 else
149 _describe -t variables 'variables' variables && ret=0
150 fi
151
152 return ret
153}
154
155_just "$@"