fix(complete): Fix bash dynamic completions

This commit is contained in:
Ed Page 2023-07-28 14:10:15 -05:00
parent 56afdabcc0
commit 12e1877627
3 changed files with 4 additions and 6 deletions

View file

@ -27,6 +27,7 @@ impl crate::dynamic::Completer for Bash {
let script = r#"
_clap_complete_NAME() {
export IFS=$'\013'
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
if compopt +o nospace 2> /dev/null; then
@ -34,7 +35,6 @@ _clap_complete_NAME() {
else
export _CLAP_COMPLETE_SPACE=true
fi
export _CLAP_COMPLETE_IFS=$'\013'
COMPREPLY=( $("COMPLETER" complete --shell bash -- "${COMP_WORDS[@]}") )
if [[ $? != 0 ]]; then
unset COMPREPLY
@ -70,9 +70,7 @@ complete -o nospace -o bashdefault -F _clap_complete_NAME BIN
let _space: Option<bool> = std::env::var("_CLAP_COMPLETE_SPACE")
.ok()
.and_then(|i| i.parse().ok());
let ifs: Option<String> = std::env::var("_CLAP_COMPLETE_IFS")
.ok()
.and_then(|i| i.parse().ok());
let ifs: Option<String> = std::env::var("IFS").ok().and_then(|i| i.parse().ok());
let completions = crate::dynamic::complete(cmd, args, index, current_dir)?;
for (i, completion) in completions.iter().enumerate() {

View file

@ -2,6 +2,7 @@ PS1='% '
. /etc/bash_completion
_clap_complete_exhaustive() {
export IFS=$'\013'
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
if compopt +o nospace 2> /dev/null; then
@ -9,7 +10,6 @@ _clap_complete_exhaustive() {
else
export _CLAP_COMPLETE_SPACE=true
fi
export _CLAP_COMPLETE_IFS=$'\013'
COMPREPLY=( $("exhaustive" complete --shell bash -- "${COMP_WORDS[@]}") )
if [[ $? != 0 ]]; then
unset COMPREPLY

View file

@ -1,5 +1,6 @@
_clap_complete_my_app() {
export IFS=$'/013'
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
if compopt +o nospace 2> /dev/null; then
@ -7,7 +8,6 @@ _clap_complete_my_app() {
else
export _CLAP_COMPLETE_SPACE=true
fi
export _CLAP_COMPLETE_IFS=$'/013'
COMPREPLY=( $("my-app" complete --shell bash -- "${COMP_WORDS[@]}") )
if [[ $? != 0 ]]; then
unset COMPREPLY