Skip to content

Commit

Permalink
Implementation of Shift + RMB click feature. (#19)
Browse files Browse the repository at this point in the history
Merging for the next major version.
  • Loading branch information
KUTlime committed May 6, 2020
1 parent b3c6d66 commit 034d6cc
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 30 deletions.
8 changes: 5 additions & 3 deletions OpenHere/OpenHere.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@
# ReleaseNotes of this module
ReleaseNotes = @'
v3.0.0: (2020-05-06)
- Support for PowerShell Core 7 RTM x64 (or any x64 major version).
- Support for WSL/Bash.
- Shell shortcut icons can be derived from shells' EXE binaries.
- New: Support for PowerShell Core 7 RTM x64 (or any x64 major version).
- New: Support for WSL/Bash.
- New: User is noticed at the beginning of shortcut configuration.
- Changed: Shell shortcut icons can be derived from shells' EXE binaries.
- Fixed: Windows Terminal shortcut to paths with '[' or ']' characters.
v2.0.5: (2020-03-01)
- Manifest description update.
Expand Down
74 changes: 51 additions & 23 deletions OpenHere/OpenHere.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ function Get-OpenHereShortcutSetup
$shellSetup.CommandExecutionValue = "pwsh.exe -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory `"%V!`" -Command `"`$host.UI.RawUI.WindowTitle = 'PowerShell $psVersion (x64)'`""
$shellSetup.CommandExecutionValueRunAs = "pwsh.exe -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory `"%V!`" -Command `"`$host.UI.RawUI.WindowTitle = 'PowerShell $psVersion (x64)'`""
$shellSetup.IconPath = ($env:Path -split ';' |
Where-Object {($_ -like '*PowerShell*') -and ($_ -notlike '*WindowsPowerShell*')} |
Sort-Object -Property Length |
Select-Object -First 1) + 'pwsh.exe'
Where-Object { ($_ -like '*PowerShell*') -and ($_ -notlike '*WindowsPowerShell*') } |
Sort-Object -Property Length |
Select-Object -First 1) + 'pwsh.exe'
}
([ShortcutType]::WindowsTerminal)
{
$shellSetup.DefaultRootName = 'Windows Terminal'
$shellSetup.RegistryKeyName = 'WindowsTerminal'
$shellSetup.ShellType = 'WindowsTerminal'
$shellSetup.CommandRoot = 'openWindowsTerminal'
$shellSetup.CommandExecutionValue = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location '%V';start-process wt -argumentList '-d .'"
$shellSetup.CommandExecutionValueRunAs = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location '%V';start-process wt -argumentList '-d .'"
$shellSetup.CommandExecutionValue = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location -LiteralPath '%V';start-process wt -argumentList '-d .'"
$shellSetup.CommandExecutionValueRunAs = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location -LiteralPath '%V';start-process wt -argumentList '-d .'"
$shellSetup.IconPath = (Get-ChildItem -Path "$env:ProgramFiles\WindowsApps" -Filter 'WindowsTerminal.exe' -Recurse |
Sort-Object -Property LastWriteTimeUtc -Descending |
Select-Object -First 1).FullName
Sort-Object -Property LastWriteTimeUtc -Descending |
Select-Object -First 1).FullName
}
Default { throw [System.ArgumentOutOfRangeException]::('Unknown Shell type.') }
}
Expand All @@ -123,6 +123,8 @@ function Set-OpenHereShortcut
Defines the elevated privileges shortcut name. If omitted, the default value "Open here as Administrator" will be used.
.PARAMETER UseExeIcon
A switch parameter which indicates that the icon from EXE binary file will be used as a shell shortcut icon.
.PARAMETER UseShift
A switch parameter which indicates that the Open Here shortcut should appear only when Shift key is pressed.
.EXAMPLE
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell
Creates the default Windows PowerShell shortcut in the system. "Windows PowerShell" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used.
Expand Down Expand Up @@ -167,10 +169,16 @@ function Set-OpenHereShortcut
Creates the default WSL Bash shortcut in the system. "WSL Bash" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used.
.EXAMPLE
PS C:\> Set-OpenHereShortcut -ShortcutType:WSLBash -UseExeIcon
Creates the default WSL Bash shortcut in the system. "WSL Bash" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used. The CMD icon will be used as the shortcut icon because the WSL Bash terminal is hosted by CMD.
Creates a customized WSL Bash shortcut in the system. "WSL Bash" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used. The CMD icon will be used as the shortcut icon because the WSL Bash terminal is hosted by CMD.
.EXAMPLE
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell
Creates the default Windows PowerShell shortcut in the system. "Windows PowerShell" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used. The native Windows PowerShell icon derived from powershell.exe will be used as the the shortcut icon.
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell -UseExeIcon
Creates a customized Windows PowerShell shortcut in the system. "Windows PowerShell" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used. The native Windows PowerShell icon derived from powershell.exe will be used as the the shortcut icon.
.EXAMPLE
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell -UseShift
Creates a customized Windows PowerShell shortcut in the system. "Windows PowerShell" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used. The shortcut will be visible in the right mouse button context menu only if SHIFT key is pressed together with the right mouse button.
.EXAMPLE
PS C:\> Set-OpenHereShortcut -ShortcutType:CMD -UseExeIcon -UseShift
Creates a customized Command prompt shortcut in the system. "Command Prompt" as root folder name, "Open here" as non-elevated privileges command name and "Open here as Administrator" elevated privileges command name will be used. The shortcut will be visible in the right mouse button context menu only if SHIFT key is pressed together with the right mouse button. The CMD icon from cmd.exe will be used as the shortcut icon.
.LINK
https://github.com/KUTlime/PowerShell-Open-Here-Module
.INPUTS
Expand Down Expand Up @@ -229,27 +237,47 @@ function Set-OpenHereShortcut
Position = 3,
ParameterSetName = 'Basic')]
[Switch]
$UseExeIcon
$UseExeIcon,
[Parameter(
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
ValueFromRemainingArguments = $false,
Position = 4,
ParameterSetName = 'Basic')]
[Switch]
$UseShift
)
$shellShortcutSetup = Get-OpenHereShortcutSetup -ShortcutType $ShortcutType
$registryKeyName = $shellShortcutSetup.RegistryKeyName
if ($RootName -eq 'Default')
{
$RootName = $shellShortcutSetup.DefaultRootName
}

Write-Host "Starting to configure Windows registry to create a new Open Here shortcut for $($shellShortcutSetup.DefaultRootName)."
function Set-RegistryKey
{
[CmdletBinding()]
param (
[Parameter()]
[String]
$Path
$Path,
[Parameter(
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
ValueFromRemainingArguments = $false,
Position = 4,
ParameterSetName = 'Basic')]
[Switch]
$UseShift
)
New-Item -Path $Path\$registryKeyName -Force -ErrorAction:Continue | Write-Verbose
New-ItemProperty -Path $Path\$registryKeyName -Name MUIVerb -Value $RootName -Force -ErrorAction:Continue | Write-Verbose
New-ItemProperty -Path $Path\$registryKeyName -Name Icon -Value $shellShortcutSetup.IconPath -Force -ErrorAction:Continue | Write-Verbose
New-ItemProperty -Path $Path\$registryKeyName -Name ExtendedSubCommandsKey -Value "Directory\ContextMenus\$registryKeyName" -Force -ErrorAction:Continue | Write-Verbose
if ($UseShift)
{
New-ItemProperty -Path $Path\$registryKeyName -Name Extended -Value '' -Force -ErrorAction:Continue | Write-Verbose
}
}

function Set-RegistryKeyWithCommand
Expand All @@ -274,16 +302,16 @@ function Set-OpenHereShortcut

New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR | Write-Verbose

Set-RegistryKey -Path HKCR:\LibraryFolder\background\shell
Set-RegistryKey -Path HKCR:\Drive\shell
Set-RegistryKey -Path HKCR:\Directory\shell
Set-RegistryKey -Path HKCR:\Directory\Background\shell
Set-RegistryKey -Path HKCR:\DesktopBackground\Shell
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Drive\shell
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\shell
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\background\shell
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\DesktopBackground\Shell
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\LibraryFolder\background\shell
Set-RegistryKey -Path HKCR:\LibraryFolder\background\shell -UseShift:$UseShift
Set-RegistryKey -Path HKCR:\Drive\shell -UseShift:$UseShift
Set-RegistryKey -Path HKCR:\Directory\shell -UseShift:$UseShift
Set-RegistryKey -Path HKCR:\Directory\Background\shell -UseShift:$UseShift
Set-RegistryKey -Path HKCR:\DesktopBackground\Shell -UseShift:$UseShift
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Drive\shell -UseShift:$UseShift
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\shell -UseShift:$UseShift
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\background\shell -UseShift:$UseShift
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\DesktopBackground\Shell -UseShift:$UseShift
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\LibraryFolder\background\shell -UseShift:$UseShift

Set-RegistryKeyWithCommand -Path HKCR:\Directory\ContextMenus
Set-RegistryKeyWithCommand -Path HKCR:\SOFTWARE\Classes\Directory\ContextMenus
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ The shortcuts will open desired shell in the current location, e.g. for Windows


# Main features
- Shortcut installation/removal for Windows PowerShell, Windows Terminal, CMD
- Shortcut installation/removal for Windows PowerShell, Windows Terminal, CMD, PowerShell Core, Bash
- Open here with non-elevated privileges shortcut.
- Open here with elevated privileges shortcut.
- Shortcut availability on **directory, drive, directory background, user's desktop**.
- Default setting for easy-to-use.
- Fully customizable shortcut names.
- Shortcut availability on **directory, drive, directory background, user's desktop**.
- Fully customizable shortcut icon.
- Capability of showing the shortcut only if the SHIFT key is pressed.
- Rollback of all shell modifications.
- Works offline.
- Well documented
- Well documented.

# Basic use
To install the OpenHere module, just type following command into your PowerShell session with elevated privileges.
Expand Down Expand Up @@ -68,6 +70,16 @@ Remove-OpenHereShortcut -ShortcutType:WindowsTerminal -Verbose
```
respectively.

For the default EXE icons as the shortcut icons, use `-UseExeIcon`:
```powershell
Set-OpenHereShortcut -ShortcutType:WindowsTerminal -UseExeIcon
```

To show the Open Here shortcut only if the SHIFT key is pressed and the right mouse button is clicked, use `-UseShift`:
```powershell
Set-OpenHereShortcut -ShortcutType:WindowsTerminal -UseShift
```

For more examples, type:
```powershell
Get-Help Set-OpenHereShortcut -Examples
Expand All @@ -83,12 +95,15 @@ Yes, see the section [Planned features.](https://github.com/KUTlime/PowerShell-O
### Can I customize the shortcut icon?
By default, OpenHere module uses its own icons in shell context menus. If the `-UseExeIcon` switch is used when shortcut is created, the default icons are **not** generated. These default icons are written in `%LOCALAPPDATA%\OpenHere\[ShellType]`. Every shell has its own `Icon.ico` file in the corresponding subfolder. You can customize icons by overriding these `Icon.ico` files.

### Can I override the names?
### Can I override the names and setup?
Yes, just run `Set-OpenHereShortcut` with a new configuration.

### Is the name limited to English?
No, the shortcut names supports Unicode and this is only limitation as I'm aware of.

### Windows Command Prompt icon looks weird when Windows Black theme is turn on. What should I do?
You could either run `Set-OpenHereShortcut` again with `-UseExeIcon` or override the icon by some other ico file. Have a look at the previous FAQ about the shortcut icon customization for details.

# Links
[OpenHere module at PowerShell Gallery](https://www.powershellgallery.com/packages/OpenHere)

Expand Down

0 comments on commit 034d6cc

Please sign in to comment.