Skip to content

Instantly share code, notes, and snippets.

@TylerLeonhardt
Last active April 21, 2020 18:54
Show Gist options
  • Save TylerLeonhardt/66f5d271d8c0c5eaccdeba0e998a91df to your computer and use it in GitHub Desktop.
Save TylerLeonhardt/66f5d271d8c0c5eaccdeba0e998a91df to your computer and use it in GitHub Desktop.
Set `cwd` when the location changes in PowerShell!

If you use iTerm, you can turn on this friendly feature:

iTerm2 feature

With this set, and the below script added to your $PROFILE, new tabs will inherit the directory of the previous one.

# Set CurrentDirectory when LocationChangedAction is invoked.
# This allows iTerm2's "Reuse previous session's directory" to work
$ExecutionContext.SessionState.InvokeCommand.LocationChangedAction += {
[Environment]::CurrentDirectory = $pwd.Path
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment