mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
fix(complete): Don't cause endless completions for bash/zsh
Reported on #5677
This commit is contained in:
parent
d81158599f
commit
0209a79031
7 changed files with 90 additions and 46 deletions
|
@ -187,15 +187,21 @@ impl CommandCompleter for Bash {
|
|||
|
||||
let script = r#"
|
||||
_clap_complete_NAME() {
|
||||
export IFS=$'\013'
|
||||
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
local IFS=$'\013'
|
||||
local _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
local _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
if compopt +o nospace 2> /dev/null; then
|
||||
export _CLAP_COMPLETE_SPACE=false
|
||||
local _CLAP_COMPLETE_SPACE=false
|
||||
else
|
||||
export _CLAP_COMPLETE_SPACE=true
|
||||
local _CLAP_COMPLETE_SPACE=true
|
||||
fi
|
||||
COMPREPLY=( $("COMPLETER" complete bash -- "${COMP_WORDS[@]}") )
|
||||
COMPREPLY=( $( \
|
||||
IFS="$IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
_CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \
|
||||
_CLAP_COMPLETE_SPACE="$_CLAP_COMPLETE_SPACE" \
|
||||
"COMPLETER" complete bash -- "${COMP_WORDS[@]}" \
|
||||
) )
|
||||
if [[ $? != 0 ]]; then
|
||||
unset COMPREPLY
|
||||
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
|
||||
|
@ -471,10 +477,14 @@ impl CommandCompleter for Zsh {
|
|||
|
||||
let script = r#"#compdef BIN
|
||||
function _clap_dynamic_completer() {
|
||||
export _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
export _CLAP_IFS=$'\n'
|
||||
local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
local _CLAP_IFS=$'\n'
|
||||
|
||||
local completions=("${(@f)$(COMPLETER complete zsh -- ${words} 2>/dev/null)}")
|
||||
local completions=("${(@f)$( \
|
||||
_CLAP_IFS="$_CLAP_IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
COMPLETER complete zsh -- ${words} 2>/dev/null \
|
||||
)}")
|
||||
|
||||
if [[ -n $completions ]]; then
|
||||
compadd -a completions
|
||||
|
|
31
clap_complete/src/env/shells.rs
vendored
31
clap_complete/src/env/shells.rs
vendored
|
@ -31,16 +31,21 @@ impl EnvCompleter for Bash {
|
|||
|
||||
let script = r#"
|
||||
_clap_complete_NAME() {
|
||||
export IFS=$'\013'
|
||||
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
local IFS=$'\013'
|
||||
local _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
local _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
if compopt +o nospace 2> /dev/null; then
|
||||
export _CLAP_COMPLETE_SPACE=false
|
||||
local _CLAP_COMPLETE_SPACE=false
|
||||
else
|
||||
export _CLAP_COMPLETE_SPACE=true
|
||||
local _CLAP_COMPLETE_SPACE=true
|
||||
fi
|
||||
export VAR="bash"
|
||||
COMPREPLY=( $("COMPLETER" -- "${COMP_WORDS[@]}") )
|
||||
COMPREPLY=( $( \
|
||||
IFS="$IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
_CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \
|
||||
VAR="bash" \
|
||||
"COMPLETER" -- "${COMP_WORDS[@]}" \
|
||||
) )
|
||||
if [[ $? != 0 ]]; then
|
||||
unset COMPREPLY
|
||||
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
|
||||
|
@ -347,11 +352,15 @@ impl EnvCompleter for Zsh {
|
|||
|
||||
let script = r#"#compdef BIN
|
||||
function _clap_dynamic_completer() {
|
||||
export _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
export _CLAP_IFS=$'\n'
|
||||
export VAR="zsh"
|
||||
local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
local _CLAP_IFS=$'\n'
|
||||
|
||||
local completions=("${(@f)$(COMPLETER -- ${words} 2>/dev/null)}")
|
||||
local completions=("${(@f)$( \
|
||||
_CLAP_IFS="$_CLAP_IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
VAR="zsh" \
|
||||
COMPLETER -- ${words} 2>/dev/null \
|
||||
)}")
|
||||
|
||||
if [[ -n $completions ]]; then
|
||||
compadd -a completions
|
||||
|
|
|
@ -2,15 +2,21 @@ PS1='% '
|
|||
. /etc/bash_completion
|
||||
|
||||
_clap_complete_exhaustive() {
|
||||
export IFS=$'\013'
|
||||
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
local IFS=$'\013'
|
||||
local _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
local _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
if compopt +o nospace 2> /dev/null; then
|
||||
export _CLAP_COMPLETE_SPACE=false
|
||||
local _CLAP_COMPLETE_SPACE=false
|
||||
else
|
||||
export _CLAP_COMPLETE_SPACE=true
|
||||
local _CLAP_COMPLETE_SPACE=true
|
||||
fi
|
||||
COMPREPLY=( $("exhaustive" complete bash -- "${COMP_WORDS[@]}") )
|
||||
COMPREPLY=( $( \
|
||||
IFS="$IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
_CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \
|
||||
_CLAP_COMPLETE_SPACE="$_CLAP_COMPLETE_SPACE" \
|
||||
"exhaustive" complete bash -- "${COMP_WORDS[@]}" \
|
||||
) )
|
||||
if [[ $? != 0 ]]; then
|
||||
unset COMPREPLY
|
||||
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#compdef exhaustive
|
||||
function _clap_dynamic_completer() {
|
||||
export _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
export _CLAP_IFS=$'\n'
|
||||
local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
local _CLAP_IFS=$'\n'
|
||||
|
||||
local completions=("${(@f)$(exhaustive complete zsh -- ${words} 2>/dev/null)}")
|
||||
local completions=("${(@f)$( \
|
||||
_CLAP_IFS="$_CLAP_IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
exhaustive complete zsh -- ${words} 2>/dev/null \
|
||||
)}")
|
||||
|
||||
if [[ -n $completions ]]; then
|
||||
compadd -a completions
|
||||
|
|
|
@ -2,16 +2,21 @@ PS1='% '
|
|||
. /etc/bash_completion
|
||||
|
||||
_clap_complete_exhaustive() {
|
||||
export IFS=$'\013'
|
||||
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
local IFS=$'\013'
|
||||
local _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
local _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
if compopt +o nospace 2> /dev/null; then
|
||||
export _CLAP_COMPLETE_SPACE=false
|
||||
local _CLAP_COMPLETE_SPACE=false
|
||||
else
|
||||
export _CLAP_COMPLETE_SPACE=true
|
||||
local _CLAP_COMPLETE_SPACE=true
|
||||
fi
|
||||
export COMPLETE="bash"
|
||||
COMPREPLY=( $("exhaustive" -- "${COMP_WORDS[@]}") )
|
||||
COMPREPLY=( $( \
|
||||
IFS="$IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
_CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \
|
||||
COMPLETE="bash" \
|
||||
"exhaustive" -- "${COMP_WORDS[@]}" \
|
||||
) )
|
||||
if [[ $? != 0 ]]; then
|
||||
unset COMPREPLY
|
||||
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#compdef exhaustive
|
||||
function _clap_dynamic_completer() {
|
||||
export _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
export _CLAP_IFS=$'\n'
|
||||
export COMPLETE="zsh"
|
||||
local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
|
||||
local _CLAP_IFS=$'\n'
|
||||
|
||||
local completions=("${(@f)$(exhaustive -- ${words} 2>/dev/null)}")
|
||||
local completions=("${(@f)$( \
|
||||
_CLAP_IFS="$_CLAP_IFS" \
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
|
||||
COMPLETE="zsh" \
|
||||
exhaustive -- ${words} 2>/dev/null \
|
||||
)}")
|
||||
|
||||
if [[ -n $completions ]]; then
|
||||
compadd -a completions
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
|
||||
_clap_complete_my_app() {
|
||||
export IFS=$'/013'
|
||||
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
local IFS=$'/013'
|
||||
local _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
local _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
if compopt +o nospace 2> /dev/null; then
|
||||
export _CLAP_COMPLETE_SPACE=false
|
||||
local _CLAP_COMPLETE_SPACE=false
|
||||
else
|
||||
export _CLAP_COMPLETE_SPACE=true
|
||||
local _CLAP_COMPLETE_SPACE=true
|
||||
fi
|
||||
COMPREPLY=( $("my-app" complete bash -- "${COMP_WORDS[@]}") )
|
||||
COMPREPLY=( $( /
|
||||
IFS="$IFS" /
|
||||
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" /
|
||||
_CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" /
|
||||
_CLAP_COMPLETE_SPACE="$_CLAP_COMPLETE_SPACE" /
|
||||
"my-app" complete bash -- "${COMP_WORDS[@]}" /
|
||||
) )
|
||||
if [[ $? != 0 ]]; then
|
||||
unset COMPREPLY
|
||||
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
|
||||
|
|
Loading…
Reference in a new issue