zsh-users
 help / color / mirror / code / Atom feed
From: Zach Riggle <zachriggle@gmail.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Collapse a file path to the shortest representation
Date: Wed, 18 May 2022 17:42:27 -0500	[thread overview]
Message-ID: <CAMP9c5kFeAWzYGuc6bQpTca=aVws9Cyoib-4dQ+EcRnNzj9XGg@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3TizsDP7D9SVoOsOKGDsX6dv=vhMv2FRMY2LTrzz6YW3w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1270 bytes --]

Thanks! It does indeed.

Is there a way to specify appearance?  ~ENV vs $ENV

        ~SOME_ENV_VAR/foo/bar
        $SOME_ENV_VAR/foo/bar

*Zach Riggle*


On Fri, May 13, 2022 at 1:03 PM Mikael Magnusson <mikachu@gmail.com> wrote:

> On 5/13/22, Zach Riggle <zachriggle@gmail.com> 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 → ~/bar/baz
> > /home/username/bar/baz → $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 ‘~’ followed by the
> name
> > of the directory ....
> >
> >
> > Is there a standardized way to access this expansion with e.g.
> > /path/to/somedir → ~SOMEDIR/foo?
>
> The D parameter expansion flag does this.
>
> --
> Mikael Magnusson
>

[-- Attachment #2: Type: text/html, Size: 2049 bytes --]

      reply	other threads:[~2022-05-18 22:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 17:53 Zach Riggle
2022-05-13 18:03 ` Mikael Magnusson
2022-05-18 22:42   ` Zach Riggle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMP9c5kFeAWzYGuc6bQpTca=aVws9Cyoib-4dQ+EcRnNzj9XGg@mail.gmail.com' \
    --to=zachriggle@gmail.com \
    --cc=mikachu@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).