Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Absolute path of a path



On Wed, 27 Oct 2010, Vincent Lefevre wrote:

On 2010-10-27 11:34:44 +0200, JÃrÃmie Roquet wrote:
2010/10/27 Nikolai Weibull>:
How do I get the absolute path of a path? ÂThe only thing I can find is the :a modifier for history expansion.

your_path(:a)

For example .(:a) is pwd

BTW, is there a way to get the canonicalised absolute pathname with zsh? (i.e. what the "realpath" command gives.)

With new enough Zsh, you can use: the ':A' modifier.

As a workaround, though, since I have to use older Zsh'es on various systems, I have:

# uses Perl, since that tends to be more consistent than 'realpath' # across the systems I was using this on:

A () { reply=("$(perl -MCwd=realpath -we 'print realpath shift' $REPLY)") }

Then, instead of:

your_path(:A)   -- returns the realpath in new Zsh'es.

you can do:

your_path(+A)   -- calls the 'A' function above to find the realpath

--
Best,
Ben


Messages sorted by: Reverse Date, Date, Thread, Author