From f1140263b2f2b0c61fb717191fe00a369b854764 Mon Sep 17 00:00:00 2001 From: szdytom <szdytom@qq.com> Date: Fri, 17 Jan 2025 20:58:38 +0800 Subject: [PATCH] Add shell completion scripts --- .SRCINFO | 9 +++++ PKGBUILD | 20 ++++++++-- vcpkg_completion.bash | 17 ++++++++ vcpkg_completion.fish | 92 +++++++++++++++++++++++++++++++++++++++++++ vcpkg_completion.zsh | 9 +++++ 5 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 vcpkg_completion.bash create mode 100644 vcpkg_completion.fish create mode 100644 vcpkg_completion.zsh diff --git a/.SRCINFO b/.SRCINFO index 88c5810..b7fb7c6 100644 --- a/.SRCINFO +++ b/.SRCINFO @@ -16,9 +16,18 @@ pkgbase = vcpkg depends = git source = vcpkg::git+https://github.com/microsoft/vcpkg-tool#tag=2024-12-09 source = vcpkg.sh + source = vcpkg_completion.bash + source = vcpkg_completion.fish + source = vcpkg_completion.zsh sha512sums = de8ea7bf516e420614a68c24c27049792996bbd967955888a6bffdf2b4075e4c703c3985deab9f6831a032bec42af64ea34ca987b054f247345353ba02107310 sha512sums = a71f4de5044197871b01d66db0453c8df228d690b259972fd4cf242806f3eac65d80e3c794ce511ce03b69f95d6c40ab20989e6fd9907efc962337d5dfbdf4f6 + sha512sums = 3e901a3dfb3c81fba8317524d46e43e25e6c1448d114d07984531521fa8fea865b8e68da2bcfaad989027e598ce53c5445321398736ea832e980f612fb1270a3 + sha512sums = 65c773fe95fe8d2ccd6dfadbe757ad98995d612ad7a44860dd6c0796ac5df67896dd1f96f887b482c29b182aed73ef8eb37b70322ce581ed205536b62a61a1f1 + sha512sums = b2af3542da99dd2fbf7495a34742279c8de54ad91eb288a98007d1c45c0cf798c5166011226764995405c94b79229f5dcef911e413feecc7e57f5c0ab90bcd25 b2sums = af6ce0683ff393229241c2bc6919ed1fd3e7c536231e7efcba8b199d1d580376d76e7aab10893d81601017430a37351c19c788eb44f00fd78ab782b928236928 b2sums = c67bb718f04146ae72ba5d7a290d08079e965cc330db11c98b94de355cd4a6ff489dbd4c363c940f4a96a1fd7ff8a754ff0efb62156e81bcccfd80376b4d0e39 + b2sums = 5508c16dc50b1413c7f5b780e2c1705019488d5636b9702190f05fc617c6b90608d35e2cc481d992f4743d749cfbd0589a141063b9121e452df4e46731092593 + b2sums = 10850078132a345fbbc93633dd33ea12fc5f3927bf0b155b2ffc945a236d0b2bb2786d72b749a9afdde8faef77b5862e12293cc2b54421d27045932813a9a9b1 + b2sums = 6934b786898ee4b16ea1fd381a5f1f15d6baa6960cc24212f1c7f3b5fde3667ac42e3bc9bbeab28026beb8ad197bf7e7b6729d538694beeb0567bf1188092ffa pkgname = vcpkg diff --git a/PKGBUILD b/PKGBUILD index 382ae7d..2879fd5 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -3,7 +3,7 @@ pkgname=vcpkg pkgver=2024.12.09 _pkgver="${pkgver//./-}" -pkgrel=1 +pkgrel=2 pkgdesc='C++ library manager' arch=('x86_64') url='https://vcpkg.io' @@ -22,11 +22,20 @@ install='vcpkg.install' source=( "$pkgname::git+https://github.com/microsoft/vcpkg-tool#tag=$_pkgver" 'vcpkg.sh' + 'vcpkg_completion.bash' + 'vcpkg_completion.fish' + 'vcpkg_completion.zsh' ) sha512sums=('de8ea7bf516e420614a68c24c27049792996bbd967955888a6bffdf2b4075e4c703c3985deab9f6831a032bec42af64ea34ca987b054f247345353ba02107310' - 'a71f4de5044197871b01d66db0453c8df228d690b259972fd4cf242806f3eac65d80e3c794ce511ce03b69f95d6c40ab20989e6fd9907efc962337d5dfbdf4f6') + 'a71f4de5044197871b01d66db0453c8df228d690b259972fd4cf242806f3eac65d80e3c794ce511ce03b69f95d6c40ab20989e6fd9907efc962337d5dfbdf4f6' + '3e901a3dfb3c81fba8317524d46e43e25e6c1448d114d07984531521fa8fea865b8e68da2bcfaad989027e598ce53c5445321398736ea832e980f612fb1270a3' + '65c773fe95fe8d2ccd6dfadbe757ad98995d612ad7a44860dd6c0796ac5df67896dd1f96f887b482c29b182aed73ef8eb37b70322ce581ed205536b62a61a1f1' + 'b2af3542da99dd2fbf7495a34742279c8de54ad91eb288a98007d1c45c0cf798c5166011226764995405c94b79229f5dcef911e413feecc7e57f5c0ab90bcd25') b2sums=('af6ce0683ff393229241c2bc6919ed1fd3e7c536231e7efcba8b199d1d580376d76e7aab10893d81601017430a37351c19c788eb44f00fd78ab782b928236928' - 'c67bb718f04146ae72ba5d7a290d08079e965cc330db11c98b94de355cd4a6ff489dbd4c363c940f4a96a1fd7ff8a754ff0efb62156e81bcccfd80376b4d0e39') + 'c67bb718f04146ae72ba5d7a290d08079e965cc330db11c98b94de355cd4a6ff489dbd4c363c940f4a96a1fd7ff8a754ff0efb62156e81bcccfd80376b4d0e39' + '5508c16dc50b1413c7f5b780e2c1705019488d5636b9702190f05fc617c6b90608d35e2cc481d992f4743d749cfbd0589a141063b9121e452df4e46731092593' + '10850078132a345fbbc93633dd33ea12fc5f3927bf0b155b2ffc945a236d0b2bb2786d72b749a9afdde8faef77b5862e12293cc2b54421d27045932813a9a9b1' + '6934b786898ee4b16ea1fd381a5f1f15d6baa6960cc24212f1c7f3b5fde3667ac42e3bc9bbeab28026beb8ad197bf7e7b6729d538694beeb0567bf1188092ffa') build() { cmake \ @@ -57,6 +66,11 @@ package() { # override environment variables install -vDm644 -t "$pkgdir/etc/profile.d" vcpkg.sh + # shell completions + install -vDm644 "vcpkg_completion.bash" "$pkgdir/usr/share/bash-completion/completions/vcpkg" + install -vDm644 "vcpkg_completion.fish" "$pkgdir/usr/share/fish/vendor_completions.d/vcpkg.fish" + install -vDm644 "vcpkg_completion.zsh" "$pkgdir/usr/share/zsh/site-functions/_vcpkg" + # license cd "$pkgname" install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.txt NOTICE.txt diff --git a/vcpkg_completion.bash b/vcpkg_completion.bash new file mode 100644 index 0000000..804507d --- /dev/null +++ b/vcpkg_completion.bash @@ -0,0 +1,17 @@ +#/usr/bin/env bash + +_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)) + + # 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" +} + +complete -F _vcpkg_completions vcpkg diff --git a/vcpkg_completion.fish b/vcpkg_completion.fish new file mode 100644 index 0000000..42e4b78 --- /dev/null +++ b/vcpkg_completion.fish @@ -0,0 +1,92 @@ +# vcpkg completions for fish +set vcpkg_executable (string split -m1 ' ' (commandline -cb))[1] + +function _vcpkg_completions + set arg (string split -m1 ' ' (commandline -cb))[2] + set curr_token (commandline -t) + if [ -n $arg ] + if [ -z $curr_token ] + set arg $arg " " + end + end + for key in ($vcpkg_executable autocomplete "$arg" -- 2>/dev/null) + echo $key + end +end + +complete -c vcpkg -f --arguments '(_vcpkg_completions)' + +set vcpkg_commands ($vcpkg_executable autocomplete) + +function _set_triplet_arguments + set triplets ($vcpkg_executable help triplet | grep "^\s" | cut -d' ' -f3) + set triplet_from "" + for triplet in $triplets + echo (test -n "$triplet") >> temp.txt + if [ (string sub -l5 -- $triplet) = "VCPKG" ] + set -l temp (string length $triplet) + set triplet_from (string sub -s6 -l(math $temp - 15) -- $triplet) + else if [ -n "$triplet" ] + complete -c vcpkg -n "__fish_seen_subcommand_from $vcpkg_commands" -x -l triplet -d "$triplet_from" -a (string sub -s3 -- $triplet) + end + end +end +_set_triplet_arguments + +# options for all completions +complete -c vcpkg -n "__fish_seen_subcommand_from $vcpkg_commands" -x -l triplet -d "Specify the target architecture triplet. See 'vcpkg help triplet' (default: \$VCPKG_DEFAULT_TRIPLET)" +complete -c vcpkg -n "__fish_seen_subcommand_from $vcpkg_commands" -x -l overlay-ports -d "Specify directories to be used when searching for ports (also: \$VCPKG_OVERLAY_PORTS)" -a '(__fish_complete_directories)' +complete -c vcpkg -n "__fish_seen_subcommand_from $vcpkg_commands" -x -l overlay-triplets -d "Specify directories containing triplets files (also: \$VCPKG_OVERLAY_TRIPLETS)" -a '(__fish_complete_directories)' +complete -c vcpkg -n "__fish_seen_subcommand_from $vcpkg_commands" -x -l binarysource -d "Add sources for binary caching. See 'vcpkg help binarycaching'" -a '(__fish_complete_directories)' +complete -c vcpkg -n "__fish_seen_subcommand_from $vcpkg_commands" -x -l downloads-root -d "Specify the downloads root directory (default: \$VCPKG_DOWNLOADS)" -a '(__fish_complete_directories)' +complete -c vcpkg -n "__fish_seen_subcommand_from $vcpkg_commands" -x -l vcpkg-root -d "Specify the vcpkg root directory (default: \$VCPKG_ROOT)" -a '(__fish_complete_directories)' + +# options for install +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l dry-run -d "Do not actually build or install" +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l head -d "Install the libraries on the command line using the latest upstream sources" +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l no-downloads -d "Do not download new sources" +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l only-downloads -d "Download sources but don't build packages" +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l recurse -d "Allow removal of packages as part of installation" +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l keep-going -d "Continue installing packages on failure" +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l editable -d "Disable source re-extraction and binary caching for libraries on the command line" +complete -c vcpkg -n "__fish_seen_subcommand_from install" -f -l clean-after-build -d "Clean buildtrees, packages and downloads after building each package" + +# options for edit +complete -c vcpkg -n "__fish_seen_subcommand_from edit" -f -l buildtrees -d "Open editor into the port-specific buildtree subfolder" +complete -c vcpkg -n "__fish_seen_subcommand_from edit" -f -l all -d "Open editor into the port as well as the port-specific buildtree subfolder" + +# options for export +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l dry-run -d "Do not actually export" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l raw -d "Export to an uncompressed directory" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l nuget -d "Export a NuGet package" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l ifw -d "Export to an IFW-based installer" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l zip -d "Export to a zip file" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l 7zip -d "Export to a 7zip (.7z) file" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l prefab -d "Export to Prefab format" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l prefab-maven -d "Enable maven" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -l prefab-debug -d "Enable prefab debug" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l output -d "Specify the output name (used to construct filename)" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l output-dir -d "Specify the output directory for produced artifacts" -a '(__fish_complete_directories)' +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l nuget-id -d "Specify the id for the exported NuGet package (overrides --output)" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l nuget-version -d "Specify the version for the exported NuGet package" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l ifw-repository-url -d "Specify the remote repository URL for the online installer" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l ifw-packages-directory-path -d "Specify the temporary directory path for the repacked packages" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l ifw-repository-directory-path -d "Specify the directory path for the exported repository" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l ifw-configuration-file-path -d "Specify the temporary file path for the installer configuration" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l ifw-installer-file-path -d "Specify the file path for the exported installer" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l prefab-group-id -d "GroupId uniquely identifies your project according maven specifications" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l prefab-artifact-id -d "Artifact Id is the name of the project according maven specifications" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l prefab-version -d "Version is the name of the project according maven specifications" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l prefab-min-sdk -d "Android minimum supported sdk version" +complete -c vcpkg -n "__fish_seen_subcommand_from export" -f -r -l prefab-target-sdk -d "Android target sdk version" + +# options for remove +complete -c vcpkg -n "__fish_seen_subcommand_from remove" -f -l purge -d "Remove the cached copy of the package (default)" +complete -c vcpkg -n "__fish_seen_subcommand_from remove" -f -l no-purge -d "Do not remove the cached copy of the package (deprecated)" +complete -c vcpkg -n "__fish_seen_subcommand_from remove" -f -l recurse -d "Allow removal of packages not explicitly specified on the command line" +complete -c vcpkg -n "__fish_seen_subcommand_from remove" -f -l dry-run -d "Print the packages to be removed, but do not remove them" +complete -c vcpkg -n "__fish_seen_subcommand_from remove" -f -l outdated -d "Select all packages with versions that do not match the portfiles" + +# options for upgrade +complete -c vcpkg -n "__fish_seen_subcommand_from upgrade" -f -l no-dry-run -d "Actually upgrade" +complete -c vcpkg -n "__fish_seen_subcommand_from upgrade" -f -l keep-going -d "Continue installing packages on failure" diff --git a/vcpkg_completion.zsh b/vcpkg_completion.zsh new file mode 100644 index 0000000..ee499f6 --- /dev/null +++ b/vcpkg_completion.zsh @@ -0,0 +1,9 @@ + +_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)) +} + +complete -F _vcpkg_completions vcpkg -- GitLab