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

Re: (:a) specifier for not existent files



On Wed, 18 Jul 2012 15:12:49 +0200
Stefan Reichör <stefan@xxxxxxxxx> wrote:
> I am using the (:a) specifier to get absoulte file paths. But this works
> only for existing files. Is there a way to make it work for not existing
> files also?

Not in general, because it can't sanity check the path so it doesn't
know what to do to it.  But you can handle some simple cases:

if [[ ! -e $1 ]]; then
  local dir=${1:h}
  if [[ -d $dir ]]; then
    dir=(${dir}(:a))
    1=${dir[1]}/${1:t}
  fi
fi

This works for names without a slash since ${1:h} returns ".".

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



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