From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9307 invoked by alias); 26 May 2018 15:07:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42852 Received: (qmail 9227 invoked by uid 1010); 26 May 2018 15:07:39 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f41.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.41):SA:0(-1.9/5.0):. Processed in 3.949505 secs); 26 May 2018 15:07:39 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: doron.behar@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=0CPEbc7yuOg/p2iGeTRG1PRgYnDMkpqHoaFtI06QJd0=; b=HBQeZQQvssr620LYCvLtwrXDn66gw+8gpSp03GoUeXLKalZ4tQ/BDdE/0iMFZ2VwpQ ghrtzVhNpletnCX+e1G5c1+X6SAoCgS0kX1c2N/oZSb2ns4dOWjDb7wOlLzuCpqdEJzJ DbINMmRVvc3FYdgW0lCv0FPnHSBRpV5DvnQPRuhGB68s2TM+uUUYNKCXusVz4CQ5OcpF Knxy62rCvGzemA9KM4+os0qVdB5nRzNALJFB8N8kmacgeXVdsrOpuXdnBvq9lAxRDg1b 89d5Vuy3ztSBWO+VsjUWuGPGbvpDs0RjH1Sxfno4oyld6+fEcP54O1MuVqcUSplTzbZV NIJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0CPEbc7yuOg/p2iGeTRG1PRgYnDMkpqHoaFtI06QJd0=; b=Qg6GOdJKGR/2NWGqno5f5Lreydacih8hn+hhXrweA0u8DXb6FvRsXAMJo91mCa/YNw v/wx5HkpJuDbOqfTif1AaNbSUysqTBu/LL5GYFN7S2JY9vDyls8tnovr5T3cg9yh7ZQ6 e9DmBoX3e7AHBRb3zVzzTE61XCipdifjLG5ADCd5wHmE6DmjriHEQMmxcQAyMgR1YQmq MmCRJRvyGwloKjXfMBSNsDsjeeGW6LbKANIXEx7H91Vtp1xEBb+oM6/nfZLcw2VU+7nh 0o983RZx83i5WFpP/+T52kValylCnH0BgPFBBr/uGM7dqa0W86h9HJiWsKpKEbePuGi5 qrpg== X-Gm-Message-State: ALKqPwfsemg5ewnNQ+5cxhihxzdEZMCeNI5fOPCWFE5FFI8JdxBylLes 3GJ12KuAs0AmqbNhBXFiz1FmFlBW X-Google-Smtp-Source: ADUXVKKkjGD3mCeWRvgRjvpcVoZWEOP/jndSfgYm7zczyFx6BfJDzjQW0VGGXYlVavo50NaB4T9toQ== X-Received: by 2002:a1c:9c52:: with SMTP id f79-v6mr4286437wme.148.1527347251832; Sat, 26 May 2018 08:07:31 -0700 (PDT) From: doron.behar@gmail.com To: zsh-workers@zsh.org Subject: [PATCH 24/25] Consider `--tree` when searching installed rocks. Date: Sat, 26 May 2018 18:06:33 +0300 Message-Id: <20180526150634.15683-25-doron.behar@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180526150634.15683-1-doron.behar@gmail.com> References: <20180526150634.15683-1-doron.behar@gmail.com> From: Doron Behar --- Completion/Unix/Command/_luarocks | 126 +++++++++++++++++++++--------- 1 file changed, 91 insertions(+), 35 deletions(-) diff --git a/Completion/Unix/Command/_luarocks b/Completion/Unix/Command/_luarocks index 8de95c188..17fa8248e 100644 --- a/Completion/Unix/Command/_luarocks +++ b/Completion/Unix/Command/_luarocks @@ -59,6 +59,7 @@ __luarocks_rock_version(){ # TODO: actually complete versions of installed rocks using the cache # How does luarocks handles multiple versions of the same package? # If anybody knows, please write something beautiful here + # TODO: get somehow from $@ the option given (if used) to --tree _message -e "version for installed rock ${words[$i]}" return ;; @@ -107,56 +108,95 @@ ___luarocks_installed_rocks_cache_policy(){ # {{{ helper: installed rocks (( $+functions[__luarocks_installed_rocks] )) || __luarocks_installed_rocks(){ - local update_policy - zstyle -s ":completion:${curcontext}:" cache-policy update_policy - if [[ -z "$update_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy - fi - if _cache_invalid luarocks_installed_list; then - rocks_list=($(luarocks list --porcelain)) - _store_cache luarocks_installed_list rocks_list + # This function optionally recieves one argument of the tree in which + # installed rocks are searched for. If this argument is used, the installed + # rocks which will be completed by this function will not use the cache which + # is valid only for installed rocks on default trees like /usr/lib/luarocks + # and ~/.luarocks + local tree="$1" + if [[ -z ${tree} ]]; then + local update_policy + zstyle -s ":completion:${curcontext}:" cache-policy update_policy + if [[ -z "$update_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy ___luarocks_installed_rocks_cache_policy + fi + if _cache_invalid luarocks_installed_list; then + rocks_list=($(luarocks list --porcelain)) + _store_cache luarocks_installed_list rocks_list + else + _retrieve_cache luarocks_installed_list + fi + if [[ -z ${rocks_list} ]]; then + _message -r "no installed rocks" + return + fi + if _cache_invalid luarocks_installed_names; then + rocks_names=() + for i in {1.."${#rocks_list[@]}"..4}; do + rocks_names+=("${rocks_list[$i]}") + done + _store_cache luarocks_installed_names rocks_names + else + _retrieve_cache luarocks_installed_names + fi + if _cache_invalid luarocks_installed_versions; then + rocks_versions=() + for i in {2.."${#rocks_list[@]}"..4}; do + rocks_versions+=("${rocks_list[$i]}") + done + _store_cache luarocks_installed_versions rocks_versions + else + _retrieve_cache luarocks_installed_versions + fi + if _cache_invalid luarocks_installed_descriptions; then + rocks_descriptions=() + for i in {1.."${#rocks_names[@]}"}; do + name_version_description="$(luarocks show ${rocks_names[$i]} 2>/dev/null | head -2 | tail -1)" + total_length=${#name_version_description} + garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))" + description="${name_version_description[${garbage_length},${total_length}]}" + rocks_descriptions+=("${description}") + done + _store_cache luarocks_installed_descriptions rocks_descriptions + else + _retrieve_cache luarocks_installed_descriptions + fi + if _cache_invalid luarocks_installed_names_and_descriptions; then + rocks_names_and_descriptions=() + for i in {1.."${#rocks_names[@]}"}; do + name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]} + rocks_names_and_descriptions+=(${name_and_description}) + done + else + _store_cache luarocks_installed_names_and_descriptions rocks_names_and_descriptions + fi else - _retrieve_cache luarocks_installed_list - fi - if _cache_invalid luarocks_installed_names; then + rocks_list=($(luarocks --tree="${tree}" list --porcelain 2> /dev/null)) + if [[ -z ${rocks_list} ]]; then + _message "no installed rocks in the specified tree" + return + fi rocks_names=() for i in {1.."${#rocks_list[@]}"..4}; do rocks_names+=("${rocks_list[$i]}") done - _store_cache luarocks_installed_names rocks_names - else - _retrieve_cache luarocks_installed_names - fi - if _cache_invalid luarocks_installed_versions; then rocks_versions=() for i in {2.."${#rocks_list[@]}"..4}; do rocks_versions+=("${rocks_list[$i]}") done - _store_cache luarocks_installed_versions rocks_versions - else - _retrieve_cache luarocks_installed_versions - fi - if _cache_invalid luarocks_installed_descriptions; then rocks_descriptions=() for i in {1.."${#rocks_names[@]}"}; do - name_version_description="$(luarocks show ${rocks_names[$i]} | head -2 | tail -1)" + name_version_description="$(luarocks show ${rocks_names[$i]} 2> /dev/null | head -2 | tail -1)" total_length=${#name_version_description} garbage_length="$((${#rocks_names[$i]} + ${#rocks_versions[$i]} + 5))" description="${name_version_description[${garbage_length},${total_length}]}" rocks_descriptions+=("${description}") done - _store_cache luarocks_installed_descriptions rocks_descriptions - else - _retrieve_cache luarocks_installed_descriptions - fi - if _cache_invalid luarocks_installed_names_and_descriptions; then rocks_names_and_descriptions=() for i in {1.."${#rocks_names[@]}"}; do name_and_description=${rocks_names[$i]}:${rocks_descriptions[$i]} rocks_names_and_descriptions+=(${name_and_description}) done - else - _store_cache luarocks_installed_names_and_descriptions rocks_names_and_descriptions fi _describe 'installed rocks' rocks_names_and_descriptions } @@ -169,21 +209,37 @@ __luarocks_installed_rocks(){ (( $+functions[__luarocks_rock] )) || __luarocks_rock(){ local -a alts=() - for arg in "$@"; do - case $arg in + while [[ $# -gt 0 ]]; do + arg="$1" + case "$arg" in (rockspec) alts+=(':rock file:{_files -g "*.rockspec"}') + shift 1 + continue ;; (rockpack) alts+=(':rock file:{_files -g "*.src.rock"}') + shift 1 + continue ;; (external) alts+=(':external rock:') + shift 1 + continue ;; (installed) - alts+=(':local rock:__luarocks_installed_rocks') + tree="$2" + alts+=(":local rock:{__luarocks_installed_rocks ${tree}}") + if [[ -z "${tree}" ]]; then + shift + else + shift 2 + fi + continue ;; esac + shift + continue done _alternative ${alts[@]} } @@ -250,7 +306,7 @@ local doc_command_options=( _luarocks_doc(){ _arguments \ "${doc_command_options[@]}" \ - '1: :{__luarocks_rock "installed"}' + '1: :{__luarocks_rock "installed" '"${opt_args[--tree]}"'}' } # }}} # {{{ `download` command @@ -383,7 +439,7 @@ local remove_command_options=( _luarocks_remove(){ _arguments -A "-*" \ "${remove_command_options[@]}" \ - '1: :{__luarocks_rock "installed"}' \ + '1: :{__luarocks_rock "installed" '"${opt_args[--tree]}"'}' \ '2:: :{__luarocks_rock_version "installed"}' } # }}} @@ -418,7 +474,7 @@ local show_command_options=( _luarocks_show(){ _arguments \ "${show_command_options[@]}" \ - '1: :{__luarocks_rock "installed"}' + "1: :{__luarocks_rock 'installed' "${opt_args[--tree]}"}" } # }}} # {{{ `unpack` command -- 2.17.0