Created
June 10, 2021 09:52
-
-
Save kyontan/41b19b3086ee7ce674add6bad1d315b0 to your computer and use it in GitHub Desktop.
envchain autocompletion (wip)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# not used, copied function body into _delegate | |
function _executables { | |
local exclude=$(compgen -abkA function | sort) | |
local executables=$( | |
comm -23 <(compgen -c) <(echo $exclude) | |
type -tP $( comm -12 <(compgen -c) <(echo $exclude) ) | |
) | |
COMPREPLY=( $(compgen -W "$executables" -- ${COMP_WORDS[COMP_CWORD]}) ) | |
} | |
function _delegate() { | |
local cur subs | |
cur="${COMP_WORDS[COMP_CWORD]}" # partial word, if any | |
subs=$(envchain -l) | |
# echo "cword: $COMP_CWORD" | |
# echo "cw: ${COMP_WORDS[COMP_CWORD]}" | |
# echo "cl: ${COMP_LINE}, ccw: ${COMP_CWORD}, cp: ${COMP_POINT}, cw3: ${COMP_WORDS[2]}" | |
if [[ $COMP_CWORD == 1 ]]; then | |
# complete with the list of subcommands | |
COMPREPLY=( $(compgen -W "${subs}" -- ${cur}) ) | |
elif [[ $COMP_CWORD == 2 ]]; then | |
# Two whole words before the cursor - delegate to the second arg | |
# echo "Delegate $1, $2" | |
# _command $2 | |
# complete -F _executables $1 | |
local exclude=$(compgen -abkA function | sort) | |
local executables=$( | |
comm -23 <(compgen -c) <(echo $exclude) | |
type -tP $( comm -12 <(compgen -c) <(echo $exclude) ) | |
) | |
COMPREPLY=( $(compgen -W "$executables" -- ${COMP_WORDS[COMP_CWORD]}) ) | |
elif [[ $COMP_CWORD == 3 ]] && [[ "${COMP_WORDS[2]}" == "aws" ]]; then | |
aws_pos=$(($(echo "$COMP_LINE" | ggrep -abo " aws " | cut -d: -f1) + 1)) | |
# echo "pos $aws_pos" | |
# echo "pos $aws_pos" | |
COMP_POINT=$((${COMP_POINT} - ${aws_pos})) | |
# echo "${COMP_LINE:aws_pos}" | |
COMP_LINE="${COMP_LINE:aws_pos}" | |
# echo "cl: ${COMP_LINE}, ccw: ${COMP_CWORD}, cp: ${COMP_POINT}" | |
# COMP_LINE=(${COMP_LINE:2}) | |
# COMP_CWORD=$((${COMP_CWORD} - 2)) | |
# COMP_POINT=$((${COMP_POINT} - 10)) | |
COMPREPLY=($(COMP_POINT=$COMP_POINT COMP_LINE=$COMP_LINE aws_completer)) | |
# COMPREPLY=( $(compgen -Cc $3 -- ${COMP_WORDS[COMP_CWORD]}) ) | |
else | |
COMPREPLY=() | |
fi | |
} | |
complete -C aws_completer aws | |
complete -F _delegate envchain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment