Skip to content

Commit 6b0aa10

Browse files
authored
Don't generate completions at runtime (#2896)
1 parent 5434a0a commit 6b0aa10

File tree

13 files changed

+807
-135
lines changed

13 files changed

+807
-135
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,10 @@ jobs:
9191
run: |
9292
rustup target add aarch64-pc-windows-msvc
9393
94-
- name: Generate Completion Scripts and Manpage
94+
- name: Generate Manpage
9595
run: |
9696
set -euxo pipefail
9797
cargo build
98-
mkdir -p completions
99-
for shell in bash elvish fish nu powershell zsh; do
100-
./target/debug/just --completions $shell > completions/just.$shell
101-
done
10298
mkdir -p man
10399
./target/debug/just --man > man/just.1
104100

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ blake3 = { version = "1.5.0", features = ["rayon", "mmap"] }
2323
camino = "1.0.4"
2424
chrono = "0.4.38"
2525
clap = { version = "4.0.0", features = ["derive", "env", "wrap_help"] }
26-
clap_complete = "=4.5.48"
2726
clap_mangen = "0.2.20"
2827
ctrlc = { version = "3.1.1", features = ["termination"] }
2928
derive-where = "1.2.7"
@@ -61,6 +60,7 @@ nix = { version = "0.30.1", features = ["user"] }
6160
ctrlc = { version = "3.1.1", features = ["termination"] }
6261

6362
[dev-dependencies]
63+
clap_complete = "=4.5.48"
6464
executable-path = "1.0.0"
6565
pretty_assertions = "1.0.0"
6666
temptree = "0.2.0"

completions/just.bash

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
_just() {
2+
local i cur prev words cword opts cmd
3+
COMPREPLY=()
4+
5+
# Modules use "::" as the separator, which is considered a wordbreak character in bash.
6+
# The _get_comp_words_by_ref function is a hack to allow for exceptions to this rule without
7+
# modifying the global COMP_WORDBREAKS environment variable.
8+
if type _get_comp_words_by_ref &>/dev/null; then
9+
_get_comp_words_by_ref -n : cur prev words cword
10+
else
11+
cur="${COMP_WORDS[COMP_CWORD]}"
12+
prev="${COMP_WORDS[COMP_CWORD-1]}"
13+
words=$COMP_WORDS
14+
cword=$COMP_CWORD
15+
fi
16+
17+
cmd=""
18+
opts=""
19+
20+
for i in ${words[@]}
21+
do
22+
case "${cmd},${i}" in
23+
",$1")
24+
cmd="just"
25+
;;
26+
*)
27+
;;
28+
esac
29+
done
30+
31+
case "${cmd}" in
32+
just)
33+
opts="-E -n -g -f -q -u -v -d -c -e -l -s -h -V --alias-style --ceiling --check --chooser --clear-shell-args --color --command-color --cygpath --dotenv-filename --dotenv-path --dry-run --dump-format --explain --global-justfile --highlight --justfile --list-heading --list-prefix --list-submodules --no-aliases --no-deps --no-dotenv --no-highlight --one --quiet --allow-missing --set --shell --shell-arg --shell-command --tempdir --timestamp --timestamp-format --unsorted --unstable --verbose --working-directory --yes --changelog --choose --command --completions --dump --edit --evaluate --fmt --groups --init --list --man --request --show --summary --variables --help --version [ARGUMENTS]..."
34+
if [[ ${cur} == -* ]] ; then
35+
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
36+
return 0
37+
else
38+
local recipes=$(just --summary 2> /dev/null)
39+
40+
if echo "${cur}" | \grep -qF '/'; then
41+
local path_prefix=$(echo "${cur}" | sed 's/[/][^/]*$/\//')
42+
local recipes=$(just --summary 2> /dev/null -- "${path_prefix}")
43+
local recipes=$(printf "${path_prefix}%s\t" $recipes)
44+
fi
45+
46+
if [[ $? -eq 0 ]]; then
47+
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
48+
if type __ltrim_colon_completions &>/dev/null; then
49+
__ltrim_colon_completions "$cur"
50+
fi
51+
return 0
52+
fi
53+
fi
54+
case "${prev}" in
55+
--alias-style)
56+
COMPREPLY=($(compgen -W "left right separate" -- "${cur}"))
57+
return 0
58+
;;
59+
--ceiling)
60+
COMPREPLY=($(compgen -f "${cur}"))
61+
return 0
62+
;;
63+
--chooser)
64+
COMPREPLY=($(compgen -f "${cur}"))
65+
return 0
66+
;;
67+
--color)
68+
COMPREPLY=($(compgen -W "always auto never" -- "${cur}"))
69+
return 0
70+
;;
71+
--command-color)
72+
COMPREPLY=($(compgen -W "black blue cyan green purple red yellow" -- "${cur}"))
73+
return 0
74+
;;
75+
--cygpath)
76+
COMPREPLY=($(compgen -f "${cur}"))
77+
return 0
78+
;;
79+
--dotenv-filename)
80+
COMPREPLY=($(compgen -f "${cur}"))
81+
return 0
82+
;;
83+
--dotenv-path)
84+
COMPREPLY=($(compgen -f "${cur}"))
85+
return 0
86+
;;
87+
-E)
88+
COMPREPLY=($(compgen -f "${cur}"))
89+
return 0
90+
;;
91+
--dump-format)
92+
COMPREPLY=($(compgen -W "json just" -- "${cur}"))
93+
return 0
94+
;;
95+
--justfile)
96+
COMPREPLY=($(compgen -f "${cur}"))
97+
return 0
98+
;;
99+
-f)
100+
COMPREPLY=($(compgen -f "${cur}"))
101+
return 0
102+
;;
103+
--list-heading)
104+
COMPREPLY=($(compgen -f "${cur}"))
105+
return 0
106+
;;
107+
--list-prefix)
108+
COMPREPLY=($(compgen -f "${cur}"))
109+
return 0
110+
;;
111+
--set)
112+
COMPREPLY=($(compgen -f "${cur}"))
113+
return 0
114+
;;
115+
--shell)
116+
COMPREPLY=($(compgen -f "${cur}"))
117+
return 0
118+
;;
119+
--shell-arg)
120+
COMPREPLY=($(compgen -f "${cur}"))
121+
return 0
122+
;;
123+
--tempdir)
124+
COMPREPLY=($(compgen -f "${cur}"))
125+
return 0
126+
;;
127+
--timestamp-format)
128+
COMPREPLY=($(compgen -f "${cur}"))
129+
return 0
130+
;;
131+
--working-directory)
132+
COMPREPLY=($(compgen -f "${cur}"))
133+
return 0
134+
;;
135+
-d)
136+
COMPREPLY=($(compgen -f "${cur}"))
137+
return 0
138+
;;
139+
--command)
140+
COMPREPLY=($(compgen -f "${cur}"))
141+
return 0
142+
;;
143+
-c)
144+
COMPREPLY=($(compgen -f "${cur}"))
145+
return 0
146+
;;
147+
--completions)
148+
COMPREPLY=($(compgen -W "bash elvish fish nushell powershell zsh" -- "${cur}"))
149+
return 0
150+
;;
151+
--list)
152+
COMPREPLY=($(compgen -f "${cur}"))
153+
return 0
154+
;;
155+
-l)
156+
COMPREPLY=($(compgen -f "${cur}"))
157+
return 0
158+
;;
159+
--request)
160+
COMPREPLY=($(compgen -f "${cur}"))
161+
return 0
162+
;;
163+
--show)
164+
COMPREPLY=($(compgen -f "${cur}"))
165+
return 0
166+
;;
167+
-s)
168+
COMPREPLY=($(compgen -f "${cur}"))
169+
return 0
170+
;;
171+
*)
172+
COMPREPLY=()
173+
;;
174+
esac
175+
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
176+
return 0
177+
;;
178+
esac
179+
}
180+
181+
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
182+
complete -F _just -o nosort -o bashdefault -o default just
183+
else
184+
complete -F _just -o bashdefault -o default just
185+
fi

completions/just.elvish

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
use builtin;
2+
use str;
3+
4+
set edit:completion:arg-completer[just] = {|@words|
5+
fn spaces {|n|
6+
builtin:repeat $n ' ' | str:join ''
7+
}
8+
fn cand {|text desc|
9+
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
10+
}
11+
var command = 'just'
12+
for word $words[1..-1] {
13+
if (str:has-prefix $word '-') {
14+
break
15+
}
16+
set command = $command';'$word
17+
}
18+
var completions = [
19+
&'just'= {
20+
cand --alias-style 'Set list command alias display style'
21+
cand --ceiling 'Do not ascend above <CEILING> directory when searching for a justfile.'
22+
cand --chooser 'Override binary invoked by `--choose`'
23+
cand --color 'Print colorful output'
24+
cand --command-color 'Echo recipe lines in <COMMAND-COLOR>'
25+
cand --cygpath 'Use binary at <CYGPATH> to convert between unix and Windows paths.'
26+
cand --dotenv-filename 'Search for environment file named <DOTENV-FILENAME> instead of `.env`'
27+
cand -E 'Load <DOTENV-PATH> as environment file instead of searching for one'
28+
cand --dotenv-path 'Load <DOTENV-PATH> as environment file instead of searching for one'
29+
cand --dump-format 'Dump justfile as <FORMAT>'
30+
cand -f 'Use <JUSTFILE> as justfile'
31+
cand --justfile 'Use <JUSTFILE> as justfile'
32+
cand --list-heading 'Print <TEXT> before list'
33+
cand --list-prefix 'Print <TEXT> before each list item'
34+
cand --set 'Override <VARIABLE> with <VALUE>'
35+
cand --shell 'Invoke <SHELL> to run recipes'
36+
cand --shell-arg 'Invoke shell with <SHELL-ARG> as an argument'
37+
cand --tempdir 'Save temporary files to <TEMPDIR>.'
38+
cand --timestamp-format 'Timestamp format string'
39+
cand -d 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set'
40+
cand --working-directory 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set'
41+
cand -c 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set'
42+
cand --command 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set'
43+
cand --completions 'Print shell completion script for <SHELL>'
44+
cand -l 'List available recipes in <MODULE> or root if omitted'
45+
cand --list 'List available recipes in <MODULE> or root if omitted'
46+
cand --request 'Execute <REQUEST>. For internal testing purposes only. May be changed or removed at any time.'
47+
cand -s 'Show recipe at <PATH>'
48+
cand --show 'Show recipe at <PATH>'
49+
cand --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.'
50+
cand --clear-shell-args 'Clear shell arguments'
51+
cand -n 'Print what just would do without doing it'
52+
cand --dry-run 'Print what just would do without doing it'
53+
cand --explain 'Print recipe doc comment before running it'
54+
cand -g 'Use global justfile'
55+
cand --global-justfile 'Use global justfile'
56+
cand --highlight 'Highlight echoed recipe lines in bold'
57+
cand --list-submodules 'List recipes in submodules'
58+
cand --no-aliases 'Don''t show aliases in list'
59+
cand --no-deps 'Don''t run recipe dependencies'
60+
cand --no-dotenv 'Don''t load `.env` file'
61+
cand --no-highlight 'Don''t highlight echoed recipe lines in bold'
62+
cand --one 'Forbid multiple recipes from being invoked on the command line'
63+
cand -q 'Suppress all output'
64+
cand --quiet 'Suppress all output'
65+
cand --allow-missing 'Ignore missing recipe and module errors'
66+
cand --shell-command 'Invoke <COMMAND> with the shell used to run recipe lines and backticks'
67+
cand --timestamp 'Print recipe command timestamps'
68+
cand -u 'Return list and summary entries in source order'
69+
cand --unsorted 'Return list and summary entries in source order'
70+
cand --unstable 'Enable unstable features'
71+
cand -v 'Use verbose output'
72+
cand --verbose 'Use verbose output'
73+
cand --yes 'Automatically confirm all recipes.'
74+
cand --changelog 'Print changelog'
75+
cand --choose 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
76+
cand --dump 'Print justfile'
77+
cand -e 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
78+
cand --edit 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
79+
cand --evaluate 'Evaluate and print all variables. If a variable name is given as an argument, only print that variable''s value.'
80+
cand --fmt 'Format and overwrite justfile'
81+
cand --groups 'List recipe groups'
82+
cand --init 'Initialize new justfile in project root'
83+
cand --man 'Print man page'
84+
cand --summary 'List names of available recipes'
85+
cand --variables 'List names of variables'
86+
cand -h 'Print help'
87+
cand --help 'Print help'
88+
cand -V 'Print version'
89+
cand --version 'Print version'
90+
}
91+
]
92+
$completions[$command]
93+
}

completions/just.fish

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
function __fish_just_complete_recipes
2+
if string match -rq '(-f|--justfile)\s*=?(?<justfile>[^\s]+)' -- (string split -- ' -- ' (commandline -pc))[1]
3+
set -fx JUST_JUSTFILE "$justfile"
4+
end
5+
printf "%s\n" (string split " " (just --summary))
6+
end
7+
8+
# don't suggest files right off
9+
complete -c just -n "__fish_is_first_arg" --no-files
10+
11+
# complete recipes
12+
complete -c just -a '(__fish_just_complete_recipes)'
13+
14+
# autogenerated completions
15+
complete -c just -l alias-style -d 'Set list command alias display style' -r -f -a "left\t''
16+
right\t''
17+
separate\t''"
18+
complete -c just -l ceiling -d 'Do not ascend above <CEILING> directory when searching for a justfile.' -r -F
19+
complete -c just -l chooser -d 'Override binary invoked by `--choose`' -r
20+
complete -c just -l color -d 'Print colorful output' -r -f -a "always\t''
21+
auto\t''
22+
never\t''"
23+
complete -c just -l command-color -d 'Echo recipe lines in <COMMAND-COLOR>' -r -f -a "black\t''
24+
blue\t''
25+
cyan\t''
26+
green\t''
27+
purple\t''
28+
red\t''
29+
yellow\t''"
30+
complete -c just -l cygpath -d 'Use binary at <CYGPATH> to convert between unix and Windows paths.' -r -F
31+
complete -c just -l dotenv-filename -d 'Search for environment file named <DOTENV-FILENAME> instead of `.env`' -r
32+
complete -c just -s E -l dotenv-path -d 'Load <DOTENV-PATH> as environment file instead of searching for one' -r -F
33+
complete -c just -l dump-format -d 'Dump justfile as <FORMAT>' -r -f -a "json\t''
34+
just\t''"
35+
complete -c just -s f -l justfile -d 'Use <JUSTFILE> as justfile' -r -F
36+
complete -c just -l list-heading -d 'Print <TEXT> before list' -r
37+
complete -c just -l list-prefix -d 'Print <TEXT> before each list item' -r
38+
complete -c just -l set -d 'Override <VARIABLE> with <VALUE>' -r
39+
complete -c just -l shell -d 'Invoke <SHELL> to run recipes' -r
40+
complete -c just -l shell-arg -d 'Invoke shell with <SHELL-ARG> as an argument' -r
41+
complete -c just -l tempdir -d 'Save temporary files to <TEMPDIR>.' -r -F
42+
complete -c just -l timestamp-format -d 'Timestamp format string' -r
43+
complete -c just -s d -l working-directory -d 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set' -r -F
44+
complete -c just -s c -l command -d 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set' -r
45+
complete -c just -l completions -d 'Print shell completion script for <SHELL>' -r -f -a "bash\t''
46+
elvish\t''
47+
fish\t''
48+
nushell\t''
49+
powershell\t''
50+
zsh\t''"
51+
complete -c just -s l -l list -d 'List available recipes in <MODULE> or root if omitted' -r
52+
complete -c just -l request -d 'Execute <REQUEST>. For internal testing purposes only. May be changed or removed at any time.' -r
53+
complete -c just -s s -l show -d 'Show recipe at <PATH>' -r
54+
complete -c just -l check -d 'Run `--fmt` in \'check\' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required.'
55+
complete -c just -l clear-shell-args -d 'Clear shell arguments'
56+
complete -c just -s n -l dry-run -d 'Print what just would do without doing it'
57+
complete -c just -l explain -d 'Print recipe doc comment before running it'
58+
complete -c just -s g -l global-justfile -d 'Use global justfile'
59+
complete -c just -l highlight -d 'Highlight echoed recipe lines in bold'
60+
complete -c just -l list-submodules -d 'List recipes in submodules'
61+
complete -c just -l no-aliases -d 'Don\'t show aliases in list'
62+
complete -c just -l no-deps -d 'Don\'t run recipe dependencies'
63+
complete -c just -l no-dotenv -d 'Don\'t load `.env` file'
64+
complete -c just -l no-highlight -d 'Don\'t highlight echoed recipe lines in bold'
65+
complete -c just -l one -d 'Forbid multiple recipes from being invoked on the command line'
66+
complete -c just -s q -l quiet -d 'Suppress all output'
67+
complete -c just -l allow-missing -d 'Ignore missing recipe and module errors'
68+
complete -c just -l shell-command -d 'Invoke <COMMAND> with the shell used to run recipe lines and backticks'
69+
complete -c just -l timestamp -d 'Print recipe command timestamps'
70+
complete -c just -s u -l unsorted -d 'Return list and summary entries in source order'
71+
complete -c just -l unstable -d 'Enable unstable features'
72+
complete -c just -s v -l verbose -d 'Use verbose output'
73+
complete -c just -l yes -d 'Automatically confirm all recipes.'
74+
complete -c just -l changelog -d 'Print changelog'
75+
complete -c just -l choose -d 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
76+
complete -c just -l dump -d 'Print justfile'
77+
complete -c just -s e -l edit -d 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
78+
complete -c just -l evaluate -d 'Evaluate and print all variables. If a variable name is given as an argument, only print that variable\'s value.'
79+
complete -c just -l fmt -d 'Format and overwrite justfile'
80+
complete -c just -l groups -d 'List recipe groups'
81+
complete -c just -l init -d 'Initialize new justfile in project root'
82+
complete -c just -l man -d 'Print man page'
83+
complete -c just -l summary -d 'List names of available recipes'
84+
complete -c just -l variables -d 'List names of variables'
85+
complete -c just -s h -l help -d 'Print help'
86+
complete -c just -s V -l version -d 'Print version'

0 commit comments

Comments
 (0)