From 55f4610bc26c03e84130b291bf9ed6162a42621d Mon Sep 17 00:00:00 2001 From: karnigen Date: Fri, 9 May 2025 21:24:52 +0200 Subject: [PATCH] Updated linux bash completion (#44961) --- scripts/vcpkg_completion.bash | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/scripts/vcpkg_completion.bash b/scripts/vcpkg_completion.bash index 804507d585..d009f738a8 100644 --- a/scripts/vcpkg_completion.bash +++ b/scripts/vcpkg_completion.bash @@ -1,17 +1,32 @@ -#/usr/bin/env bash +#!/usr/bin/env bash +# set -x + +# To install: +# > vcpkg integrate bash +# This adds the following line to ~/.bashrc: +# source ~/vcpkg/scripts/vcpkg_completion.bash + +# Details: bash and utilities from bash-completion +# Bash commands: compgen, complete +# Input: COMP_WORDS, COMP_CWORD, COMP_LINE, COMP_POINT, COMP_KEY, COMP_WORDBREAKS +# Output: COMPREPLY _vcpkg_completions() { - local vcpkg_executable=${COMP_WORDS[0]} - local remaining_command_line=${COMP_LINE:(${#vcpkg_executable}+1)} - COMPREPLY=($(${vcpkg_executable} autocomplete "${remaining_command_line}" -- 2>/dev/null)) + local vcpkg_executable=${COMP_WORDS[0]} + local remaining_command_line=${COMP_LINE:(${#vcpkg_executable}+1)} + # echo "rem:$remaining_command_line" - # Colon is treated as a delimiter in bash. The following workaround - # allows triplet completion to work correctly in the syntax: - # zlib:x64-windows - local cur - _get_comp_words_by_ref -n : cur - __ltrim_colon_completions "$cur" + if [ $COMP_CWORD -eq 1 ]; then + local opts=$(${vcpkg_executable} autocomplete ${remaining_command_line}) + else + local opts=$(${vcpkg_executable} autocomplete ${remaining_command_line} --) + fi + #echo "opts:$opts" + + COMPREPLY=($(compgen -W "${opts}" -- ${COMP_WORDS[COMP_CWORD]}) ) + #echo "COMPREPLY:$COMPREPLY" } complete -F _vcpkg_completions vcpkg +