-
Notifications
You must be signed in to change notification settings - Fork 513
Shortcut to change the current directory in the PowerShell console to the currently opened file? #2189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
(NOTE: All of this code must be run in the PowerShell Integrated Console) You would do it like this in script: Set-Location ([IO.Path]::GetDirectoryName($PSEditor.GetEditorContext().CurrentFile.Path)) You could register an Editor Command to be quick about it: Register-EditorCommand -Name ChangeToDir -DisplayName "Change to the Directory of the Current File" -ScriptBlock {
Set-Location ([IO.Path]::GetDirectoryName($PSEditor.GetEditorContext().CurrentFile.Path))
} Then you can do:
Then find |
Thank you for the response. It works. Is there no way to assign a keyboard shortcut directly to "ChangeToDir"? |
Not currently due to #2145, but after that's fixed it'll be possible. |
Thank you |
I found a better solution from StackOverflow that works in both the cmd and PowerShell consoles. (Better because it is a keyboard shortcut and not a menu selection.) In the keybindings.json file, add the following key binding: { |
I am running the PowerShell extension in Visual Studio Code with its PowerShell Integrated Console attached. I have two PowerShell scripts each open in separate tabs. The files are located in different directories.
I would like to quickly change the current directory to the currently active tab in the PowerShell console using a keyboard shortcut (e.g. Ctrl+Alt+D).
How does one accomplish this?
https://stackoverflow.com/questions/57893791
The text was updated successfully, but these errors were encountered: