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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30321 invoked from network); 13 May 2022 17:55:12 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 May 2022 17:55:12 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1652464512; b=GWeiXUJRoACxdOWpWDXSSFlQCdZI2Iswbk4MDQT3g2HAlhM90UuphGAeLNzTVERNHigvRNFncK BR5BlaJVITaSw0e4KtFPyOKuEEjn6cgWyXSvA0VhgM4RIp/wIcQfyZHypeim6cRXAhVGek39A3 6fRRq74Fj1GMy7v8vcNJk6Vikgkz7S8f+iGFrmyLS79t9USN2Zh5hSZjug2Yrve5ZZsRyRwgOA BlpkT75ies9yYPRFgtZoR9GZu1dzvlqo/8wpwJ1ajuui0oDT6ylYlwEFXomAUvr27YMp5htkWI BBzjV+R2V4Bvl48p5o1UPHJoVYO7fCdKJM3NKErtp59Rkg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1652464512; bh=7euRf3CztDmb7m7YyeF0C63CdhmPcQWxKtQnVyolKSA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=EP2fH05zotV/gGXdbzswdbvJY2zSUdxffo6EhACNRKDlMjcom9RlyIWl6H/iPGiXwFMaw0d/yY PtoUJa1vBfLqp5Q7qEEaa2m+Uu+iQ7G0pjVoo+pcHDgwmrlPzzkccUqnuQwZ/5NAmO1/os3YwB d7iVonEof3IOgr/nsf5QRhIsEPUlEvb12PMmHklIE9Lih9kUQDgR/S1UfCS311d7nrSkLb+WCB u+HNWrmdvQVRWnxYnAW9nBoZ5WsBU7nBIgRkN1P/5w3Rpi9hXDHQk9qIrKJkHT3DBV3+UPo5om jFP2ADa+Q91zwK9brsq2OVa9jHNdZVyK8j+eTzFxdvcqgg==; 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:To:Subject:Message-ID: Date:From:MIME-Version: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=7euRf3CztDmb7m7YyeF0C63CdhmPcQWxKtQnVyolKSA=; b=Q9h40nXNnH/0cuTl/GTNFJVNU5 MHdaTjNCEPPoApVDPZE2yt9hxmlSu/mg1ULLn5pvnkeUGgzwY1TxLNarmrwIQ5zO5Fc1qi6Nzl1wk JWhfDqauOaUZjBVmiiiKs8QMEGzdPtkC/01lgTOqSeDoIbnOgGNIUcuA9dYr93uzkPAHVGrCLK/W0 CPhE1DA3BgTv7FCZ64qoNypkU8IKaEtgKOQcFBphiJDtMc/zDeMeUpCBRCw1YB3qn1HTb2KzJYqyc bjh8KhI5xO7UVQH32tdvzq6PpcT+iSZCBNve3ut4l1Q3kb5bSlA1B+ahiVr1IsBkU5cwZijguWz0p pQewshbg==; Received: from authenticated user by zero.zsh.org with local id 1npZVO-0004ue-LO; Fri, 13 May 2022 17:55:10 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wr1-f47.google.com ([209.85.221.47]:36852) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1npZU5-0004Ag-69; Fri, 13 May 2022 17:53:49 +0000 Received: by mail-wr1-f47.google.com with SMTP id u3so12412448wrg.3 for ; Fri, 13 May 2022 10:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=7euRf3CztDmb7m7YyeF0C63CdhmPcQWxKtQnVyolKSA=; b=FDLMilMs3+6zr4xXRDC8SQCMS/6ntspqXvSZBY2u5+w8L9+h7ae7yPBMvmqXYLR65W Jihc8D9sMNRCQnXdTGfn/1w3ob9kK5vXD7I5JNQgL/aafhzBSFz+bgD5BGXbvsrBbKkL 7uaRB3OtpJPzZDVUjT8ZSgh4k9B6pNfrZHtaB+K+qQiTqMMSp6Kle7s4pdDqp1C5i0Br DT4g4tJw16AUjElXtlbp3qCfK2vkibCF7xT4y4cIsyt5QfwMWzsdixQi7sDWZKk8YJNq ei3+q/Wsx8UwrHIKzfQsDRaL2CUlbxi2BcDJZyepsfePABcQIDu7GHnEtlrqiQJdKHQ8 2fAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=7euRf3CztDmb7m7YyeF0C63CdhmPcQWxKtQnVyolKSA=; b=6d6Ao/BnTH3j4k4s43PzOPQ3EvQySWKtiIynISs3nGZLpviL68eEoN6NZo5YvpK55P iW1psQaYPfkXHTp88QBo0qS531R0pM6glisST1m9hpzXOazD/kWtOoMNODgnymlAHbJf CjeP0CW05gwUMVehcTov3a3d0pvkFNsUmxHs2wceWx84POHRGarp7O0iRClBQFj8hHWC L9+1UiCdrKJtijkbJbfufSvf2b9jOSFKoPt3xw4JRX0XnMfYEpLWN4vtNSsP3pveIP/K MZv0vcX6OZhh6ZUwXH+l4NToQU8UNNhCcbprYEbESiruTIgorglOUWDUuic8RoSCOyJw DTHw== X-Gm-Message-State: AOAM530b1nY28entOTJixItes/bhfFJaxxGm+Oecl39ODODNKTgq69D/ lNTJ1sVU4AWoSPnhjOmQt6H5n+uq8DUmrY1StJkvf6WD+kI= X-Google-Smtp-Source: ABdhPJyPx9p7xkGjnzWcmewX2xRuq/TFtp61qdbI/HXthg9EqNc0Abt0VBrO0OaaM7/PT3usQH+oxxB2boC9JWCtDXw= X-Received: by 2002:a5d:6843:0:b0:20a:def2:5545 with SMTP id o3-20020a5d6843000000b0020adef25545mr4945039wrw.89.1652464428337; Fri, 13 May 2022 10:53:48 -0700 (PDT) MIME-Version: 1.0 From: Zach Riggle Date: Fri, 13 May 2022 12:53:37 -0500 Message-ID: Subject: Collapse a file path to the shortest representation To: Zsh Users Content-Type: multipart/alternative; boundary="000000000000414ddb05dee85b90" X-Seq: 27757 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --000000000000414ddb05dee85b90 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Is there a ZSH standard way to collapse a file path to its shortest representation that would be idempotent per Chapter 14.7? For example, one might echo "$filepath" | sed -E "s|$HOME/?|~/|" echo "$filepath" | sed -E "s|$HOME/?|\$HOME/|" In order to turn /home/username/bar/baz =E2=86=92 ~/bar/baz /home/username/bar/baz =E2=86=92 $HOME/bar/baz To achieve this effect. >From the documentation, "14.7 Filename Expansion" has a lot of ways that paths can be expanded, including... 14.7.2 ... the path is checked to see if it has a named directory as its prefix. If so, then the prefix portion is replaced with a =E2=80=98~=E2=80=99 follo= wed by the name of the directory .... Is there a standardized way to access this expansion with e.g. /path/to/somedir =E2=86=92 ~SOMEDIR/foo? I expect this can be implemented manually by parsing the output of "hash -d" or similar, but I figured it was worth asking if there's an easy interface to this. I'm not concerned as much about "14.7.1 Dynamic named directories" but for completeness it would be neat. *Zach Riggle* --000000000000414ddb05dee85b90 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Is there a ZSH standard way to collapse a file path to its= shortest representation that would be idempotent per Chapter 14.7?
For example, one might

echo "$filepath"= | sed -E "s|$HOME/?|~/|"
echo "$filepath" | = sed -E "s|$HOME/?|\$HOME/|"

=
In order to turn

/home/username/bar/baz =E2=86=92 ~/bar/= baz
/home/username/bar/baz =E2=86=92 $HOME/bar/baz

To achieve this effect.=C2=A0=C2=A0
<= br>
From the documentation, "14.7 Filename Expansion" h= as a lot of ways that paths can be expanded, including...

14.7.2
... the path is checked to see if it has a named directo= ry as its prefix. If so, then the prefix portion is replaced with a =E2=80= =98~=E2=80=99 followed by the name of the directory ....

Is there a standardized way to access this expansion with= e.g. /path/to/somedir =E2=86=92 ~SOMEDIR/foo?

I expect this can be impleme= nted manually by parsing the output of "hash -d" or similar, but = I figured it was worth asking if there's an easy interface to this.

I= 9;m not concerned as much about "14.7.1 Dynamic named directories"= ; but for completeness it would be neat.

Zach Riggle

--000000000000414ddb05dee85b90--