diff --git a/shell_completion/silkaj-bash-complete.sh b/shell_completion/silkaj-bash-complete.sh new file mode 100644 index 0000000000000000000000000000000000000000..843b529ac827f654357e3c7179478de3750f34c1 --- /dev/null +++ b/shell_completion/silkaj-bash-complete.sh @@ -0,0 +1,21 @@ +_silkaj_completion() { + local IFS=$' +' + COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ + COMP_CWORD=$COMP_CWORD \ + _SILKAJ_COMPLETE=complete $1 ) ) + return 0 +} + +_silkaj_completionetup() { + local COMPLETION_OPTIONS="" + local BASH_VERSION_ARR=(${BASH_VERSION//./ }) + # Only BASH version 4.4 and later have the nosort option. + if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then + COMPLETION_OPTIONS="-o nosort" + fi + + complete $COMPLETION_OPTIONS -F _silkaj_completion silkaj +} + +_silkaj_completionetup; diff --git a/shell_completion/silkaj-zsh-complete.sh b/shell_completion/silkaj-zsh-complete.sh new file mode 100644 index 0000000000000000000000000000000000000000..3667592f6203e7f5da4d7ec5d342ea0b08fb0862 --- /dev/null +++ b/shell_completion/silkaj-zsh-complete.sh @@ -0,0 +1,28 @@ +_silkaj_completion() { + local -a completions + local -a completions_with_descriptions + local -a response + response=("${(@f)$( env COMP_WORDS="${words[*]}" \ + COMP_CWORD=$((CURRENT-1)) \ + _SILKAJ_COMPLETE="complete_zsh" \ + silkaj )}") + + for key descr in ${(kv)response}; do + if [[ "$descr" == "_" ]]; then + completions+=("$key") + else + completions_with_descriptions+=("$key":"$descr") + fi + done + + if [ -n "$completions_with_descriptions" ]; then + _describe -V unsorted completions_with_descriptions -U -Q + fi + + if [ -n "$completions" ]; then + compadd -U -V unsorted -Q -a completions + fi + compstate[insert]="automenu" +} + +compdef _silkaj_completion silkaj;