From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI, PDS_OTHER_BAD_TLD,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24231 invoked from network); 7 Jan 2022 09:27:54 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Jan 2022 09:27:54 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1641547674; b=TRW8l0HO02vgwFveb85lZBUnNlUpKKglZ4KHsOLL4Cgz/J5n7+bIuWTleR4QW+s9ZY/Czodt5w J1biyk+Q05dRMnVg41YHDnpJmNi3/Kdb6isXEf3hbxuDeF9pM20RxsbMStiH69fabyrV8h9NDl ouyYTI5kYNKgJFcC/PhlZ7gCQYG6EYClsuWRq+NXfqHGUEA7HuJfTyfT5giAtZqdHVg6JbBzEp jEp/awsWg9slC2J7qJEEBPJX5pe9lhaM4DoBYf4Cj0f4/3LgUq6tr5b/OC1OUXal+vcZ3HmU/N R5XPjsF0c1/3KpvxFu2MrxNHHobxw38fW5S8P4tpmMacDw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (liselle.bunkus.org) smtp.remote-ip=144.76.140.85; dkim=pass header.d=bunkus.online header.s=dkim header.a=rsa-sha256; dmarc=pass header.from=bunkus.online; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1641547674; bh=peCK7IHMTQno07ypIKWdUResMiB9IliiBeFgHrJzG4c=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:MIME-Version:Message-ID:Date:Subject:To:From: DKIM-Signature:DKIM-Signature; b=Dq/fm2YSA3uw4s6MXafbqHRS8l7Kvoi2SS/aeAJUGl5l3nGO7VhI0jaikD+KKG7rJ+l0ej7i8/ L+FgwonJlo6cjUzP56yoABvFoVE7zswiv0ASGPYg5ovRpST26S1b36V0IRHuPwm0u6KuoqAo/H H+qM7ulnNmK6NFtsVUEj19+w2WO1k3GsbgiQVWMxazY+JIDzIGv+yrwnrfr19Vne7dAwZbz4tv kOdqHxTis0LB3Bo6ZWh03tUGl0a9diiKVhr/qAy7E76qeDenLQabCrQ5ztff708A0k65FRCbWo F/af9AAa9e9vOn/gqn6/xX5zPsC/LT5UhDQCcGaEOkLaEQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=VL+Sw0+0iAajXkUR+eQrH7/fQnMIFLbr4i+clHxJftk=; b=k21H4/BQ0UGWxCT1PBxi4IUphW B3/EtEVawZOhQOH4mWY6D1ieC05fu9XwwnSReEoP6Httzfhf2OpDiSeaTvSjPVVtZWINl2cRlra0P qFwpzezM3YQVZ49VZsRpBXS3uQdsc5EhceHlxoOx+o48gSU3/qXYxO0/brru+YakUlIAPvXtHX1Jg P4hkQGVGKbQiJmF3Q8lTqkT8zRgSqh2irG1LyA8oOkoFBxX4aHCWEyrpySly8cpJuV9waJT7b2NRU 6ld3B6LmOkSjHEnx7jKzW+vPvE49b/S/xn7V5+KJ2p3NFzIFGUAIguimG6Lo/QwuRwmalNmQZ350A 1pz71iEQ==; Received: from authenticated user by zero.zsh.org with local id 1n5lXL-000LvD-4r; Fri, 07 Jan 2022 09:27:51 +0000 Authentication-Results: zsh.org; iprev=pass (liselle.bunkus.org) smtp.remote-ip=144.76.140.85; dkim=pass header.d=bunkus.online header.s=dkim header.a=rsa-sha256; dmarc=pass header.from=bunkus.online; arc=none Received: from liselle.bunkus.org ([144.76.140.85]:50674) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1n5lWg-000LZM-K4; Fri, 07 Jan 2022 09:27:11 +0000 Received: from sweet-chili.int.bunkus.org (sweet-chili.int.bunkus.org [192.168.191.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) (Authenticated sender: email-relay) by liselle.bunkus.org (Postfix) with ESMTPSA id 4997729528F9 for ; Fri, 7 Jan 2022 10:27:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bunkus.online; s=dkim; t=1641547628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=VL+Sw0+0iAajXkUR+eQrH7/fQnMIFLbr4i+clHxJftk=; b=poVETnB9CwDkdYt4L2PMzjhZ5CSzOpFFpf1XstdHr99fTnpWDvqxyvIP6llql+YrAvp0s+ uEkKh7wobNgRqTibEIfAUjQPa4JCt4ND/ifb+41wRvGWY7gqPwBbz6+ZzrLOM3JKiz+CFu Kt7Z8MK/O8zDj3pmggNZpf2XVCO63rw= Received: from sweet-chili (localhost [IPv6:::1]) by sweet-chili.int.bunkus.org (Postfix) with ESMTP id F28AA8A21648 for ; Fri, 7 Jan 2022 10:27:07 +0100 (CET) User-agent: mu4e 1.6.10; emacs 27.2 From: Moritz Bunkus To: zsh-workers@zsh.org Subject: Ansible tab completion: re-read cached hosts & groups on directory change Date: Fri, 07 Jan 2022 10:21:12 +0100 Message-ID: <877dbbopzo.fsf@bunkus.online> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Seq: 49676 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --=-=-= Content-Type: text/plain Hey, zsh 5.8 we have several Ansible repositories in different directories. I often have to switch between them. Unfortunately the tab completion for all the Ansible commands caches known Hosts & Groups in the global variables _ansible_hosts & _ansible_groups. For me the effect is that the wrong set of hosts & groups is offered when I change to a different Ansible repo. How to reproduce: 1. Have two or more Ansible repositories with different inventories somewhere 2. cd into /path/to/first_ansible_tree 3. Type `anssible `, let tab completion cache hosts & groups 4. Hit again to verify that the offered completions match expected ones 5. cd into /path/to/other_ansible_tree 6. Type `ansible ` and observe that the offered completions still come from the first_ansible_tree, not from other_ansible_tree As a quick workaround I've modified the completion to also cache the working directory where _ansible_hosts & _ansible_groups were created. If the current working directory doesn't match the cached working directory, both variables are unset & their values cached again. This seems to work. The attached patch implements this. Feel free to use it however you want, or to apply a totally different solution. Thanks. Kind regards, mosu --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=ansible-uncache-hosts-on-directory-change.diff --- /usr/share/zsh/functions/Completion/Unix/_ansible 2020-02-16 18:55:21.000000000 +0100 +++ /home/mosu/.config/zsh/functions/_ansible 2022-01-07 09:43:00.841820539 +0100 @@ -204,10 +204,15 @@ else local -a inventory typeset -ga _ansible_hosts _ansible_groups + typeset -g _ansible_inventory_last_cwd + if [[ $PWD != $_ansible_inventory_last_cwd ]]; then + unset _ansible_hosts _ansible_groups + fi if (( !$#_ansible_hosts || !$#_ansible_groups )); then inventory=( ${(f)"$(_call_program groups ansible-inventory --graph)"} ) _ansible_hosts=( ${${(M)inventory%--[^:]#}#--} ) _ansible_groups=( ${${${(M)inventory%@*:}%:}#@} ) + _ansible_inventory_last_cwd=$PWD fi [[ $IPREFIX = *[:,] ]] && alts=( 'operators:operator:_values -S "" operator "![exclude hosts]" "&[intersection of hosts]" "~[regular expression pattern]"' ) --=-=-=--