From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 8E1B31F852 for ; Thu, 13 Jan 2022 00:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236350AbiAMAAn (ORCPT ); Wed, 12 Jan 2022 19:00:43 -0500 Received: from pb-smtp1.pobox.com ([64.147.108.70]:63983 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236349AbiAMAAj (ORCPT ); Wed, 12 Jan 2022 19:00:39 -0500 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id C06F5100358; Wed, 12 Jan 2022 19:00:36 -0500 (EST) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=cmwCJnIRFmMUH4jhiN0EexSLPA8ZASekeuz/Ky wLMzQ=; b=sfinB7LrJKl0Jkva58TX2prKM+dLQIjzZ8OiojZctlDQL/nGMZv2tk hIVJxmcOeine6NNIgfrdAP6FUFx9A/gUoIVEfdJ8rDaBBwUiMFBC287PxXmfPvI4 WSyhFvhvqjhxtWk43wdqjLC8138CXE4ElNW3NMDq+J9LLC8ek79S4= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id B6E54100357; Wed, 12 Jan 2022 19:00:36 -0500 (EST) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [104.133.2.91]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 0394E100355; Wed, 12 Jan 2022 19:00:35 -0500 (EST) (envelope-from junio@pobox.com) From: Junio C Hamano To: Lessley Dennington Cc: Lessley Dennington via GitGitGadget , git@vger.kernel.org, stolee@gmail.com, johannes.schindelin@gmail.com, Elijah Newren Subject: Re: [PATCH v3 3/3] sparse-checkout: limit tab completion to a single level References: <0e4bb6f1-337e-38b3-75b2-fe11ff8d68b2@gmail.com> Date: Wed, 12 Jan 2022 16:00:34 -0800 In-Reply-To: <0e4bb6f1-337e-38b3-75b2-fe11ff8d68b2@gmail.com> (Lessley Dennington's message of "Wed, 12 Jan 2022 15:43:26 -0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: D5AE6D80-7403-11EC-A105-5E84C8D8090B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Lessley Dennington writes: >> + # Find possible directory completions, adding trailing '/' characters >> + _tmp_completions="$(git ls-tree -d --name-only HEAD $_tmp_dir | >> + sed -e s%$%/%)" >> + > I am admittedly unfamiliar with the use of this format in sed expressions > (I'm generally more accustomed to '/' instead of '%'). It's definitely > working as it should, I'm just not quite sure of how. The substitution operator "s" in "sed" can take any letter as the match-replacement delimiter. People use 's/match/replacement/' usually because that is how textbooks teach them, but whatever letter chosen as the delimiter, if it appears in either match or replacement, it needs to be quoted, i.e. 's/match/replace\/ment/'. Using a delimiter letter other than '/' relieves you from having to quote a slash when slash is part of match-replacement. Even though it is more common to use a letter that is a more clearly delimiter looking, e.g. "s|match|replace/ment|", it is not a crime to use letters like '%' and '#', or even 's' ;-) >> + if [[ -n "$_tmp_completions" ]]; then >> + # There were some directory completions, so find ones that >> + # start with "$cur", the current token, and put those in COMPREPLY >> + local i=0 c IFS=$' \t\n' > Does c need to be declared before the loop? >> + for c in $_tmp_completions; do bash completion script runs in the same namespace as the end-user's interactive session, so we MUST be careful not to contaminate the namespace or clobber variable the end-user is using. "local c" before we use $c for our own use is a way to make sure that when this function that says "local c" is left, the value (or non-presence) of "c" is restored to its original value before this function was entered.