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=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24502 invoked from network); 13 Dec 2020 04:41:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Dec 2020 04:41:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1607834467; b=VRsLolR5atnJtwwNBr2vZZ/kNLnA05qV2w/inc99kQtg+Q1xhpXX1312sT9mjipB/uji5VLsyT In/X3KgVNUvxKDoPOno6BNZPhEFTQy0TZmBfFtKKtqKk00Wjo4XH99v5Qb0+2si1mFJCPA08vO gV+1+IDQHDuCDuDoQD6BWW6kPM9SGjIjR778yTx4zj9HBplr2CufxRHIjZBIFj749WP68ggC6i aD17FeDJTz1j8IZwbFKP14gR8HOs1FD5k6m5hcUGJOCEEhAGvn+aJoBvpZbpI4u0ScXoRoosUM AX/IWRVBImNww3o19eZvvuI6FeniJQQBaW4cdXVXrowzYQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-il1-f179.google.com) smtp.remote-ip=209.85.166.179; dkim=pass header.d=dana-is.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=dana.is; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1607834467; bh=lDhK8kVf7YuQPFpCatzyXPS156x7AuPWeQOKLtmr4b4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:Date:Message-ID:Subject:MIME-Version: Content-Transfer-Encoding:Content-Type:From:DKIM-Signature:DKIM-Signature; b=iYABVGzabDqVqiovG78wfL/7ed10EgXtLnu/XwCCJV5N2GNin86BOx/0T6VqoElNOBsfQJvlx0 erIzBWSqxhQ6+uAjDaoowTTT1yV7OzYVsHb7eRwKMjNMlt/eg8EmFcu9OF8In2yLv5aZI3J+Q7 kbf+hwfM2WKWKgt1DwDYR8UEiU9yvHxZY86DUu2PUhFpJlvFtj8bPVmSo6/K0CqGprFml68+qB Ql/Hq8CIH5/C8CaTEN5xjvhLYGPHtTk3rJyC8MdMNkt9tK4KD9WXciclVYMx7oDbcUfrkYPkeK HXsJ9rhkIrIKpWHv7X55afW4T1C4B3KH2vsAUNXT07rCoQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:To:Date:Message-Id:Subject: Mime-Version:Content-Transfer-Encoding:Content-Type:From:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=fvy/LGK/tUq+887rBmfIOLgruhu9Ohm5ycxFNvkkWGU=; b=XVzH6AkoJ+2mwrYr4LIEquGbBc OXJ0mKp0SKRYrJPJaSkLdlJFgSBhpe59Oj/4iMNI0CxKFTIefwyDDBTlDlKHDIsehczXpeq7OFgKJ XfAB7u7/1HNBRPMFAU2utJmbxSqj5ZGsGzcc1i+9qdJGhhKIrOlbWSLNAT/BR2uDPzcPWv1+XIn1f PP2SyfPQMdQBU4l/ila52cPXdxMkI1Z0XZwLz9jymxuLwcTiYIO2RsSDgmdYCfMQLAUFMW7hxGNKb 3Wu4mqP4W/1j0qgfFkIpbWdyVjQTDoJ3Vn7WEJdA6H1el1Z6D1kOTexmBgHGMlw9NE67/mltrM2nY /RtKQ9bA==; Received: from authenticated user by zero.zsh.org with local id 1koJBx-0008ao-Oc; Sun, 13 Dec 2020 04:41:05 +0000 Authentication-Results: zsh.org; iprev=pass (mail-il1-f179.google.com) smtp.remote-ip=209.85.166.179; dkim=pass header.d=dana-is.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=dana.is; arc=none Received: from mail-il1-f179.google.com ([209.85.166.179]:37830) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1koJBe-0008Ss-9M; Sun, 13 Dec 2020 04:40:46 +0000 Received: by mail-il1-f179.google.com with SMTP id k8so12714247ilr.4 for ; Sat, 12 Dec 2020 20:40:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=fvy/LGK/tUq+887rBmfIOLgruhu9Ohm5ycxFNvkkWGU=; b=k4moGQoSSzkjD28/ovp9xt6OtfG87gpStp7B/dpR/JPNcCi7rs2Uq7GiyB8QllX+DW EsYBW/zSYOYnrbqiEXSzFE5FkgUK8F/VGkr3ucZsjpUCO4vow0bBbPs8pZQ7aX46Atz+ Cu2OwWZRRYnQYnBP2Wz7EW6yeGci6PuVKCdV4AtZ9OWOlJfgRixM7Udg4ynVPvno07jC 4Ix+NAqPms8pY7ix0Dwcsg4psDhTvftvhs/zWNJatySlWOe8l1HCpcInI/luEQwdtJJ4 0yHzpE4yhFRPQsWo1Hrf/NFKExgeUo5on8Hzi8dGTOedra9vyDl6uPUKsaJnRJaZAK2S Zszg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=fvy/LGK/tUq+887rBmfIOLgruhu9Ohm5ycxFNvkkWGU=; b=JLB1C5wbnxw0vjJ4l0XXT9eQ5K8b5amNBitTHqBflR7u5Lp6qIHhIRdUFl0LUggSTm RtC+9KToVsqkcAheMucLQ3IySpAr4iaqi0cyrD6Yww3dW/VRwfyY9ru9PoUyRUo3TsEH CYohh3ZHyv6m5uC1P8HUIti86V78FjNULok0IsiyiYCs6BkU0Awd26PZ3b5OKRE7/zvX E1WC4TyQor7MJ0yNOza+hiCWnRZT5vPj1tgQBFOYgYinIEin4S1sa0+lHgWb6yRdg8Ua yuVAnqFHTIygE1gDlN46eftTTSo6OL6/Zog4SmDquGOeG/hnMoljQ7PBKTIex1ZCLTqB 6ohQ== X-Gm-Message-State: AOAM530g/5ChUa4O2gqvzURq9R0r9XF/dq60vXnC0FTy9EfDP/J7Nt1p 1UxBzjXdJOwMW/nh1V31JxlR20EIWyyleA== X-Google-Smtp-Source: ABdhPJyz5+I8PnwtcqB3EgZ9yDDJqD9zpB4kvKnMuuUIB9YgmI6QqueuOPPVvNvNQyb2DRF2EHTWgQ== X-Received: by 2002:a92:ab0f:: with SMTP id v15mr26397720ilh.17.1607834444567; Sat, 12 Dec 2020 20:40:44 -0800 (PST) Received: from heartswap.lan.dana.is (173-17-84-59.client.mchsi.com. [173.17.84.59]) by smtp.gmail.com with ESMTPSA id v22sm8824397ila.84.2020.12.12.20.40.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Dec 2020 20:40:44 -0800 (PST) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: [RFC] Case-insensitive path completion in _git Message-Id: Date: Sat, 12 Dec 2020 22:40:43 -0600 To: Zsh hackers list X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Seq: 47738 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: Archived-At: I've had this sitting for a while: _git has issues completing files case-insensitively (if you have = matcher-list 'm:{a-zA-Z}=3D{A-Za-z}' or whatever). Looking into it, i found that = __git_files is trying to pass a glob pattern to `git ls-files`, and this fails if = there's not an exact case match, since ls-files is always case-sensitive. There is a fall-back to `git ls-files` with no path, but this doesn't = always work either, because it defaults to the CWD, and the file you're trying = to complete may not be under the CWD. Even when the fall-back succeeds, = it's not ideal, because it'll pass every single file in the tree to _multi_parts, = which can be slow. The following hack solves the problem for me, but it might be too silly = to commit. Can anyone think of a more proper fix? If not, would the hack be viable (probably gated behind a style)? dana diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 81a060e4d..7d0201efe 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -7138,6 +7138,7 @@ __git_files_relative () { (( $+functions[__git_files] )) || __git_files () { local compadd_opts opts tag description gittoplevel gitprefix files = expl + local MATCH MBEGIN MEND =20 zparseopts -D -E -a compadd_opts V+: J+: 1 2 o+: n f x+: X+: M+: P: = S: r: R: q F: zparseopts -D -E -a opts -- -cached -deleted -modified -others = -ignored -unmerged -killed x+: --exclude+: @@ -7152,14 +7153,26 @@ __git_files () { =20 # TODO: --directory should probably be added to $opts when --others = is given. =20 + # ls-files allows the part of the path under the repository directory = to be a + # glob pattern. However, these patterns are always case-sensitive = (even if the + # file system is not). This means that if we have a matcher style set = to make + # path completion case-insensitive, it won't (necessarily) work, = because we + # won't get any results back from Git. To work around this, we can = transform + # the pattern from abc to [Aa][Bb][Cc]. This is very dumb, but = seemingly + # reliable enough local pref=3D${(Q)${~PREFIX}} + pref=3D${pref//(#m)[[:alpha:]]/\[${(U)MATCH}${(L)MATCH}\]} [[ $pref[1] =3D=3D '/' ]] || pref=3D$gittoplevel$gitprefix$pref =20 # First allow ls-files to pattern-match in case of remote repository files=3D(${(0)"$(_call_program files git ls-files -z = --exclude-standard ${(q)opts} -- ${(q)${pref:+$pref\*}:-.} = 2>/dev/null)"}) __git_command_successful $pipestatus || return =20 - # If ls-files succeeded but returned nothing, try again with no = pattern + # If ls-files succeeded but returned nothing, try again with no = pattern. Note + # that ls-files defaults to the CWD if not given a path, so if the = file we + # were trying to add is in an *adjacent* directory, this won't return = anything + # helpful. (If it did, the case-sensitivity issue mentioned above = would only + # be a minor performance issue rather than a complete failure to = return) if [[ -z "$files" && -n "$pref" ]]; then files=3D(${(0)"$(_call_program files git ls-files -z = --exclude-standard ${(q)opts} -- 2>/dev/null)"}) __git_command_successful $pipestatus || return