Support recipe paths containing ::
in Bash completion script (#1863)
This commit is contained in:
parent
daf4520a2b
commit
e92ee922de
@ -1,12 +1,23 @@
|
|||||||
_just() {
|
_just() {
|
||||||
local i cur prev opts cmds
|
local i cur prev words cword opts cmds
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
# Modules use "::" as the separator, which is considered a wordbreak character in bash.
|
||||||
|
# The _get_comp_words_by_ref function is a hack to allow for exceptions to this rule without
|
||||||
|
# modifying the global COMP_WORDBREAKS environment variable.
|
||||||
|
if type _get_comp_words_by_ref &>/dev/null; then
|
||||||
|
_get_comp_words_by_ref -n : cur prev words cword
|
||||||
|
else
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
words=$COMP_WORDS
|
||||||
|
cword=$COMP_CWORD
|
||||||
|
fi
|
||||||
|
|
||||||
cmd=""
|
cmd=""
|
||||||
opts=""
|
opts=""
|
||||||
|
|
||||||
for i in ${COMP_WORDS[@]}
|
for i in ${words[@]}
|
||||||
do
|
do
|
||||||
case "${i}" in
|
case "${i}" in
|
||||||
"$1")
|
"$1")
|
||||||
@ -24,7 +35,7 @@ _just() {
|
|||||||
if [[ ${cur} == -* ]] ; then
|
if [[ ${cur} == -* ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
return 0
|
return 0
|
||||||
elif [[ ${COMP_CWORD} -eq 1 ]]; then
|
elif [[ ${cword} -eq 1 ]]; then
|
||||||
local recipes=$(just --summary 2> /dev/null)
|
local recipes=$(just --summary 2> /dev/null)
|
||||||
|
|
||||||
if echo "${cur}" | \grep -qF '/'; then
|
if echo "${cur}" | \grep -qF '/'; then
|
||||||
@ -35,6 +46,9 @@ _just() {
|
|||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
|
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
|
||||||
|
if type __ltrim_colon_completions &>/dev/null; then
|
||||||
|
__ltrim_colon_completions "$cur"
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -207,4 +207,37 @@ pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
|
|||||||
fi"#,
|
fi"#,
|
||||||
),
|
),
|
||||||
(r" just)", r#" "$1")"#),
|
(r" just)", r#" "$1")"#),
|
||||||
|
(
|
||||||
|
r"local i cur prev opts cmds",
|
||||||
|
r"local i cur prev words cword opts cmds",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
r#" cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}""#,
|
||||||
|
r#"
|
||||||
|
# Modules use "::" as the separator, which is considered a wordbreak character in bash.
|
||||||
|
# The _get_comp_words_by_ref function is a hack to allow for exceptions to this rule without
|
||||||
|
# modifying the global COMP_WORDBREAKS environment variable.
|
||||||
|
if type _get_comp_words_by_ref &>/dev/null; then
|
||||||
|
_get_comp_words_by_ref -n : cur prev words cword
|
||||||
|
else
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
words=$COMP_WORDS
|
||||||
|
cword=$COMP_CWORD
|
||||||
|
fi
|
||||||
|
"#,
|
||||||
|
),
|
||||||
|
(r"for i in ${COMP_WORDS[@]}", r"for i in ${words[@]}"),
|
||||||
|
(
|
||||||
|
r"elif [[ ${COMP_CWORD} -eq 1 ]]; then",
|
||||||
|
r"elif [[ ${cword} -eq 1 ]]; then",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
r#"COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )"#,
|
||||||
|
r#"COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
|
||||||
|
if type __ltrim_colon_completions &>/dev/null; then
|
||||||
|
__ltrim_colon_completions "$cur"
|
||||||
|
fi"#,
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user