diff options
Diffstat (limited to 'mingling_core/tmpls')
| -rw-r--r-- | mingling_core/tmpls/comps/bash.sh | 43 | ||||
| -rw-r--r-- | mingling_core/tmpls/comps/zsh.zsh | 8 |
2 files changed, 35 insertions, 16 deletions
diff --git a/mingling_core/tmpls/comps/bash.sh b/mingling_core/tmpls/comps/bash.sh index 1af4f6c..edec28d 100644 --- a/mingling_core/tmpls/comps/bash.sh +++ b/mingling_core/tmpls/comps/bash.sh @@ -1,22 +1,31 @@ #!/usr/bin/env bash _<<<bin_name>>>_bash_completion() { - local cur="${COMP_WORDS[COMP_CWORD]}" + local line="${COMP_LINE:0:COMP_POINT}" + local cur="${line##* }" local prev="" - [ $COMP_CWORD -gt 0 ] && prev="${COMP_WORDS[COMP_CWORD-1]}" + local word_index=1 - local word_index=$((COMP_CWORD + 1)) + local before="${line:0:$(( ${#line} - ${#cur} ))}" + local -a before_words + if [[ -n "$before" ]]; then + read -ra before_words <<< "$before" + word_index=$(( ${#before_words[@]} + 1 )) + if [[ $word_index -gt 1 ]]; then + prev="${before_words[${#before_words[@]}-1]}" + fi + fi local args=() - args+=(-f="${COMP_LINE//-/^}") - args+=(-C="$COMP_POINT") - args+=(-w="${cur//-/^}") - args+=(-p="${prev//-/^}") - args+=(-c="${COMP_WORDS[0]//-/^}") - args+=(-i="$word_index") - args+=(-F="bash") + args+=(-f "${COMP_LINE//-/^}") + args+=(-C "$COMP_POINT") + args+=(-w "${cur//-/^}") + args+=(-p "${prev//-/^}") + args+=(-c "${COMP_WORDS[0]//-/^}") + args+=(-i "$word_index") + args+=(-F "bash") for word in "${COMP_WORDS[@]}"; do - args+=(-a="${word//-/^}") + args+=(-a "${word//-/^}") done local suggestions @@ -36,7 +45,17 @@ _<<<bin_name>>>_bash_completion() { [ -z "$cur" ] || [[ "$suggestion" == "$cur"* ]] && filtered+=("$suggestion") done - [ ${#filtered[@]} -gt 0 ] && COMPREPLY=("${filtered[@]}") + if [ ${#filtered[@]} -gt 0 ]; then + COMPREPLY=("${filtered[@]}") + if [[ "$cur" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then + local colon_prefix="${cur%"${cur##*:}"}" + local -a ltrimmed=() + for suggestion in "${COMPREPLY[@]}"; do + ltrimmed+=("${suggestion#"$colon_prefix"}") + done + COMPREPLY=("${ltrimmed[@]}") + fi + fi return fi fi diff --git a/mingling_core/tmpls/comps/zsh.zsh b/mingling_core/tmpls/comps/zsh.zsh index c1c18bb..f665133 100644 --- a/mingling_core/tmpls/comps/zsh.zsh +++ b/mingling_core/tmpls/comps/zsh.zsh @@ -38,9 +38,9 @@ _<<<bin_name>>>_completion() { local -a parsed_completions for item in "${completions[@]}"; do if [[ "$item" =~ '^([^$]+)\$\((.+)\)$' ]]; then - parsed_completions+=("${match[1]}:${match[2]}") + parsed_completions+=("${match[1]//:/\\:}:${match[2]}") else - parsed_completions+=("$item") + parsed_completions+=("${item//:/\\:}") fi done @@ -48,8 +48,8 @@ _<<<bin_name>>>_completion() { _describe '<<<bin_name>>> commands' parsed_completions else local -a simple_completions - for item in "${parsed_completions[@]}"; do - if [[ "$item" =~ '^([^:]+):(.+)$' ]]; then + for item in "${completions[@]}"; do + if [[ "$item" =~ '^([^$]+)\$\((.+)\)$' ]]; then simple_completions+=("${match[1]}") else simple_completions+=("$item") |
