Search code examples
powershellterminalwindows-terminal

Windows Terminal and PowerShell - Custom Keyboard Shortcut


I have added in my PowerShell profile functions to set locations as following:

function myPath {set-location "D:\SomePath\"}

Now when I call it in Windows Terminal with PowerShell the command myPath it redirects to the specific one. With the command start . I can open this directory in Windows Explorer. Is there any way that I can introduce custom keyboard shortcuts that will open Window Explorer to the current directory like Ctrl+E to replace somehow start . command?


Solution

  • Try the following, using the built-in PSReadLine module's Set-PSReadLineKeyHandler cmdlet:

    Set-PSReadLineKeyHandler -Chord 'ctrl+e' { Invoke-Item $PWD.ProviderPath }
    

    Pressing Ctrl+E should then bring up the host platform's file browser, showing the current directory.


    Note that an alternative to defining a keyboard shortcut is to submit the following command, which uses the built-in ii alias for the Invoke-Item cmdlet:

    ii .