zsh-users
 help / color / mirror / code / Atom feed
* Implement CDPATH mechanism in Zsh script
@ 2016-09-03 21:52 Sebastian Gniazdowski
  2016-09-07  6:04 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-03 21:52 UTC (permalink / raw)
  To: Zsh Users

Hello,
I need to determine how CWD changed after: cd "not-absolute-path" –
and do this in Zsh script. How to re-implement that mechanism in
script? Any neat tricks or maybe an official way?

Best regards,
Sebastian Gniazdowski


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Implement CDPATH mechanism in Zsh script
  2016-09-03 21:52 Implement CDPATH mechanism in Zsh script Sebastian Gniazdowski
@ 2016-09-07  6:04 ` Bart Schaefer
  2016-09-07  6:13   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-09-07  6:04 UTC (permalink / raw)
  To: Zsh Users

On Sep 3, 11:52pm, Sebastian Gniazdowski wrote:
}
} I need to determine how CWD changed after: cd "not-absolute-path" -
} and do this in Zsh script. How to re-implement that mechanism in
} script? Any neat tricks or maybe an official way?

Do you mean something other than comparing $OLDPWD to $PWD ?

Or are you trying to predict how the current directory is going to be
changed by "cd", without actually executing "cd"?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Implement CDPATH mechanism in Zsh script
  2016-09-07  6:04 ` Bart Schaefer
@ 2016-09-07  6:13   ` Sebastian Gniazdowski
  2016-09-07  7:52     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-07  6:13 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

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

On 7 September 2016 at 08:04, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> Do you mean something other than comparing $OLDPWD to $PWD ?
>
> Or are you trying to predict how the current directory is going to be
> changed by "cd", without actually executing "cd"?
>

Ah, it's about prediction

Best regards,
Sebastian Gniazdowski

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Implement CDPATH mechanism in Zsh script
  2016-09-07  6:13   ` Sebastian Gniazdowski
@ 2016-09-07  7:52     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-09-07  7:52 UTC (permalink / raw)
  To: Zsh Users

On Sep 7,  8:13am, Sebastian Gniazdowski wrote:
}
} On 7 September 2016 at 08:04, Bart Schaefer <schaefer@brasslantern.com>
} wrote:
} 
} > Or are you trying to predict how the current directory is going to be
} > changed by "cd", without actually executing "cd"?
} 
} Ah, it's about prediction

The most obvious/foolproof thing would be to use a subshell:

    newPWD=$(cd -q $where >&/dev/null && pwd)

Next would be globbing:

    # Assumes last component of $cdpath is "."
    cdWD=( $^cdpath/$where(N[1]) )
    newPWD=${cdWD:A}

Note this is exactly what :A is supposed to be for, but it gives the
wrong result if CHASE_LINKS or CHASE_DOTS is set, so you may need the
new :P modifier, or the :a modifier instead.  [[ -o ... ]] tests left
as an exercise.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-09-07  7:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-03 21:52 Implement CDPATH mechanism in Zsh script Sebastian Gniazdowski
2016-09-07  6:04 ` Bart Schaefer
2016-09-07  6:13   ` Sebastian Gniazdowski
2016-09-07  7:52     ` Bart Schaefer

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).