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,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 522 invoked from network); 13 May 2022 18:14:20 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 May 2022 18:14:20 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1652465660; b=FXG5N1Vna6Cu4I4BOjJCATBmCN1S0wJGqJVbHX2yOnhocmMsAw+DWAEEkbIr8+9W/trwQNp3Yh Bb5OEFfl5RZeFiT+yqvg2bMMRWTwnHoVLA1gBMS849XpGCrqRqLsqr7ZRlxMux9OaiV2wHr9A7 hIB6ZwXiJ71FsuTqop+7rA6x6ZUZMTo+viXSw3n/O7mkVBUERRo8ptaEA44l/JSZCGQKdxsjXs IzwjE5mNAftrwboPe2p7isvV4X5uuTfYj2MGLURYX4/5/jG0Asv+pVbRkPM3RZs0mJDPyAepf9 qPnXxBVf5HoKtVfI/4C+AdhkAVZuI1dPXZsW33yUq65HWw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-pf1-f181.google.com) smtp.remote-ip=209.85.210.181; 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=1652465660; bh=wiFYmb3m254rUheT4j5/R6fuguwI1aFwQs7veFP7HTY=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:References:In-Reply-To:MIME-Version:DKIM-Signature: DKIM-Signature; b=aPJYLrdKq7LYVuafMzX1rMHh+Ynf6zCO8G0FOEZhlt523xWD0CMGDjHdBYELjQUr6GMNbWOCbP jl3vPED2VtVvux7XA5M7SVglFYEhuNZdWKlkWRKKYHC/+RCMAfww9fByr1H+1/cwLZGRiDfs3h /S+uHVC+c0pfMFdUb379nJ9sRv0/TaFZl0yKHaSpPY5gM7Q/rw4WLeVnLcwHL/lvU7d8g0AKh8 seO+cyjCnZbPc1zvDeFpaW3+/6T1+ha0MLXlg2pY+nlGeaT4MX3oQvWcscbhHWC+EWH6qh4RJg vVxFKG/EclFADYpU4D/IMmhyFXjflxYWKd1ff5I7pcPUFA==; 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-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:References:In-Reply-To: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=wiFYmb3m254rUheT4j5/R6fuguwI1aFwQs7veFP7HTY=; b=AcObEtPriu5oEk8+iRxNwRrDYX bR/68CBTvx8Aje1okytH71XSzB10wAHGTyKN79PjtgI0EbOqdLMYPrl2Plf+vW6Z9Vt+90MSDdj4y brKZNX2116vfQ14dCm8WbYmLU8sJ5pYKrzoGXZdC+2xT0Nsx0EuJ+YgDe/pT/XCL1caq4wIR9iBvM F5b/+cbJsjbrj2XPMzPvcyPQaI9dBNliQKzus0Kp4sUMgtcXpLe+YwOH22eZEDHbh31TwWA+L9m2z Wqn8iXc5zAALfsM0tun7ZAVlMcBrZDlbQ0b9AdQ1FdIZ/WABJES3+otxFvb9ijwsRqf5IJ+TK25SP 1K1w7z1w==; Received: from authenticated user by zero.zsh.org with local id 1npZnw-0006sO-1k; Fri, 13 May 2022 18:14:20 +0000 Authentication-Results: zsh.org; iprev=pass (mail-pf1-f181.google.com) smtp.remote-ip=209.85.210.181; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-pf1-f181.google.com ([209.85.210.181]:45615) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1npZds-0005Um-Gn; Fri, 13 May 2022 18:03:56 +0000 Received: by mail-pf1-f181.google.com with SMTP id y41so8300959pfw.12 for ; Fri, 13 May 2022 11:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=wiFYmb3m254rUheT4j5/R6fuguwI1aFwQs7veFP7HTY=; b=HCxN0p6NMZWJNVB+L++YFENEB63a8nql5dhWtV6I/itZKc3H5VnNJxeLMLsW/B+VvC tEHZZipRPaacuhPWgKoNjS78bbRCCp10ugRfj8YRWMuVTTQsXjCGzF1/fGSPklkN47vo UwxNTEksE2AncFcR7V+EqN+v3Xce411H4ttzyuPLvENd2pdA5LtmbbrdZYaAl22l85sX OcPydupVQuJpchWazQl1zLKWs33sCKaCkcgnJSBFhS8pe2Bp0BKRRDdCSZn81bxaNxJJ +1N8TvqvGN6uxK5vM0NbxuEdHxuaforgHwYblox92igjjUeNhlKFI3fTnUj5tDLItNQL 0lCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=wiFYmb3m254rUheT4j5/R6fuguwI1aFwQs7veFP7HTY=; b=lENV354bbFHIjVkOwyTlDjYrCzdpbqhojAP/Xai+2zfHNmEXGanRZ82iEfwC1fDrkl jePh6JylUAHh0axC7HriH1UU3Y5yNj6bmEFISFrpw25CS3ruYLLJTcRzX0/ZaRYdaPqG n9RAE74tZDaGORnjCWqFMVoxz+OZumcq4TQeSKkfF0wYHSf1L3E/flf7lJQ45BotVt4I 1Ht3WwFLOStNLcFWWPcDmYCVOw5APXatNZpYIK62kj+pJruT5S5VTPoJIv1WvdIE4A/W o/0chqzapj8jVMn84Mqv7OGX2Y2SAmSJnELDXGmlH9a/2ciJl2v72J1Mn4E4raAdT9CQ 4EYA== X-Gm-Message-State: AOAM53318vJVtmNCV9WkT6b4bkbf2YLdErDesA9yo9z0DiEa7ma+W7B9 FZ1IoNoofurXzGtuxiVGtbim/PuEXrCVyWfg4LQ= X-Google-Smtp-Source: ABdhPJwiafCCHZhDrtf8tE2uuQ25NECQ9x5bz68aIgNDzJgGM60+pZJ/QJ/degKhof3DeffVgRmnJ0cRlLan3ILPcQw= X-Received: by 2002:aa7:8046:0:b0:510:88c8:7cbf with SMTP id y6-20020aa78046000000b0051088c87cbfmr5634741pfm.50.1652465035220; Fri, 13 May 2022 11:03:55 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6a10:e897:0:0:0:0 with HTTP; Fri, 13 May 2022 11:03:54 -0700 (PDT) In-Reply-To: References: From: Mikael Magnusson Date: Fri, 13 May 2022 20:03:54 +0200 Message-ID: Subject: Re: Collapse a file path to the shortest representation To: Zach Riggle Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 27758 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: On 5/13/22, Zach Riggle wrote: > 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 fol= lowed 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? The D parameter expansion flag does this. --=20 Mikael Magnusson