powershell - How can I run a command after a cd ($pwd changes)? -
i want run command going file .mything-rc
in current directory. want check if file exist when cd
.
i mean, command not going call set-location
, want execute automatically if user call set-location
... nvm
in bash, when cd
in folder .nvmrc
automatically runs command nvm use ...
how can detect $pwd
changed , run command?
you append custom scriptblock
existing prompt
function check directory change , whatever want:
$currentprompt = (get-command prompt).scriptblock $newlogic = { $global:old = $global:new; $global:new = get-location; if($null -ne $global:old -and $global:new.path -ne $global:old.path){ write-host "location changed '$global:old' '$global:new'." } } $newprompt = [scriptblock]::create("$currentprompt; $newlogic") function prompt { & $newprompt }
note relies on global variables should of course choose better variable name old
, new
.
Comments
Post a Comment