Skip to content

Commit 034d6cc

Browse files
authored
Implementation of Shift + RMB click feature. (#19)
Merging for the next major version.
1 parent b3c6d66 commit 034d6cc

File tree

3 files changed

+75
-30
lines changed

3 files changed

+75
-30
lines changed

OpenHere/OpenHere.psd1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@
112112
# ReleaseNotes of this module
113113
ReleaseNotes = @'
114114
v3.0.0: (2020-05-06)
115-
- Support for PowerShell Core 7 RTM x64 (or any x64 major version).
116-
- Support for WSL/Bash.
117-
- Shell shortcut icons can be derived from shells' EXE binaries.
115+
- New: Support for PowerShell Core 7 RTM x64 (or any x64 major version).
116+
- New: Support for WSL/Bash.
117+
- New: User is noticed at the beginning of shortcut configuration.
118+
- Changed: Shell shortcut icons can be derived from shells' EXE binaries.
119+
- Fixed: Windows Terminal shortcut to paths with '[' or ']' characters.
118120
119121
v2.0.5: (2020-03-01)
120122
- Manifest description update.

OpenHere/OpenHere.psm1

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ function Get-OpenHereShortcutSetup
8484
$shellSetup.CommandExecutionValue = "pwsh.exe -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory `"%V!`" -Command `"`$host.UI.RawUI.WindowTitle = 'PowerShell $psVersion (x64)'`""
8585
$shellSetup.CommandExecutionValueRunAs = "pwsh.exe -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory `"%V!`" -Command `"`$host.UI.RawUI.WindowTitle = 'PowerShell $psVersion (x64)'`""
8686
$shellSetup.IconPath = ($env:Path -split ';' |
87-
Where-Object {($_ -like '*PowerShell*') -and ($_ -notlike '*WindowsPowerShell*')} |
88-
Sort-Object -Property Length |
89-
Select-Object -First 1) + 'pwsh.exe'
87+
Where-Object { ($_ -like '*PowerShell*') -and ($_ -notlike '*WindowsPowerShell*') } |
88+
Sort-Object -Property Length |
89+
Select-Object -First 1) + 'pwsh.exe'
9090
}
9191
([ShortcutType]::WindowsTerminal)
9292
{
9393
$shellSetup.DefaultRootName = 'Windows Terminal'
9494
$shellSetup.RegistryKeyName = 'WindowsTerminal'
9595
$shellSetup.ShellType = 'WindowsTerminal'
9696
$shellSetup.CommandRoot = 'openWindowsTerminal'
97-
$shellSetup.CommandExecutionValue = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location '%V';start-process wt -argumentList '-d .'"
98-
$shellSetup.CommandExecutionValueRunAs = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location '%V';start-process wt -argumentList '-d .'"
97+
$shellSetup.CommandExecutionValue = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location -LiteralPath '%V';start-process wt -argumentList '-d .'"
98+
$shellSetup.CommandExecutionValueRunAs = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -noprofile -command Set-Location -LiteralPath '%V';start-process wt -argumentList '-d .'"
9999
$shellSetup.IconPath = (Get-ChildItem -Path "$env:ProgramFiles\WindowsApps" -Filter 'WindowsTerminal.exe' -Recurse |
100-
Sort-Object -Property LastWriteTimeUtc -Descending |
101-
Select-Object -First 1).FullName
100+
Sort-Object -Property LastWriteTimeUtc -Descending |
101+
Select-Object -First 1).FullName
102102
}
103103
Default { throw [System.ArgumentOutOfRangeException]::('Unknown Shell type.') }
104104
}
@@ -123,6 +123,8 @@ function Set-OpenHereShortcut
123123
Defines the elevated privileges shortcut name. If omitted, the default value "Open here as Administrator" will be used.
124124
.PARAMETER UseExeIcon
125125
A switch parameter which indicates that the icon from EXE binary file will be used as a shell shortcut icon.
126+
.PARAMETER UseShift
127+
A switch parameter which indicates that the Open Here shortcut should appear only when Shift key is pressed.
126128
.EXAMPLE
127129
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell
128130
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.
@@ -167,10 +169,16 @@ function Set-OpenHereShortcut
167169
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.
168170
.EXAMPLE
169171
PS C:\> Set-OpenHereShortcut -ShortcutType:WSLBash -UseExeIcon
170-
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.
172+
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.
171173
.EXAMPLE
172-
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell
173-
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.
174+
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell -UseExeIcon
175+
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.
176+
.EXAMPLE
177+
PS C:\> Set-OpenHereShortcut -ShortcutType:WindowsPowerShell -UseShift
178+
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.
179+
.EXAMPLE
180+
PS C:\> Set-OpenHereShortcut -ShortcutType:CMD -UseExeIcon -UseShift
181+
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.
174182
.LINK
175183
https://github.com/KUTlime/PowerShell-Open-Here-Module
176184
.INPUTS
@@ -229,27 +237,47 @@ function Set-OpenHereShortcut
229237
Position = 3,
230238
ParameterSetName = 'Basic')]
231239
[Switch]
232-
$UseExeIcon
240+
$UseExeIcon,
241+
[Parameter(
242+
ValueFromPipeline = $true,
243+
ValueFromPipelineByPropertyName = $true,
244+
ValueFromRemainingArguments = $false,
245+
Position = 4,
246+
ParameterSetName = 'Basic')]
247+
[Switch]
248+
$UseShift
233249
)
234250
$shellShortcutSetup = Get-OpenHereShortcutSetup -ShortcutType $ShortcutType
235251
$registryKeyName = $shellShortcutSetup.RegistryKeyName
236252
if ($RootName -eq 'Default')
237253
{
238254
$RootName = $shellShortcutSetup.DefaultRootName
239255
}
240-
256+
Write-Host "Starting to configure Windows registry to create a new Open Here shortcut for $($shellShortcutSetup.DefaultRootName)."
241257
function Set-RegistryKey
242258
{
243259
[CmdletBinding()]
244260
param (
245261
[Parameter()]
246262
[String]
247-
$Path
263+
$Path,
264+
[Parameter(
265+
ValueFromPipeline = $true,
266+
ValueFromPipelineByPropertyName = $true,
267+
ValueFromRemainingArguments = $false,
268+
Position = 4,
269+
ParameterSetName = 'Basic')]
270+
[Switch]
271+
$UseShift
248272
)
249273
New-Item -Path $Path\$registryKeyName -Force -ErrorAction:Continue | Write-Verbose
250274
New-ItemProperty -Path $Path\$registryKeyName -Name MUIVerb -Value $RootName -Force -ErrorAction:Continue | Write-Verbose
251275
New-ItemProperty -Path $Path\$registryKeyName -Name Icon -Value $shellShortcutSetup.IconPath -Force -ErrorAction:Continue | Write-Verbose
252276
New-ItemProperty -Path $Path\$registryKeyName -Name ExtendedSubCommandsKey -Value "Directory\ContextMenus\$registryKeyName" -Force -ErrorAction:Continue | Write-Verbose
277+
if ($UseShift)
278+
{
279+
New-ItemProperty -Path $Path\$registryKeyName -Name Extended -Value '' -Force -ErrorAction:Continue | Write-Verbose
280+
}
253281
}
254282

255283
function Set-RegistryKeyWithCommand
@@ -274,16 +302,16 @@ function Set-OpenHereShortcut
274302

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

277-
Set-RegistryKey -Path HKCR:\LibraryFolder\background\shell
278-
Set-RegistryKey -Path HKCR:\Drive\shell
279-
Set-RegistryKey -Path HKCR:\Directory\shell
280-
Set-RegistryKey -Path HKCR:\Directory\Background\shell
281-
Set-RegistryKey -Path HKCR:\DesktopBackground\Shell
282-
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Drive\shell
283-
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\shell
284-
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\background\shell
285-
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\DesktopBackground\Shell
286-
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\LibraryFolder\background\shell
305+
Set-RegistryKey -Path HKCR:\LibraryFolder\background\shell -UseShift:$UseShift
306+
Set-RegistryKey -Path HKCR:\Drive\shell -UseShift:$UseShift
307+
Set-RegistryKey -Path HKCR:\Directory\shell -UseShift:$UseShift
308+
Set-RegistryKey -Path HKCR:\Directory\Background\shell -UseShift:$UseShift
309+
Set-RegistryKey -Path HKCR:\DesktopBackground\Shell -UseShift:$UseShift
310+
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Drive\shell -UseShift:$UseShift
311+
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\shell -UseShift:$UseShift
312+
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\Directory\background\shell -UseShift:$UseShift
313+
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\DesktopBackground\Shell -UseShift:$UseShift
314+
Set-RegistryKey -Path HKLM:\SOFTWARE\Classes\LibraryFolder\background\shell -UseShift:$UseShift
287315

288316
Set-RegistryKeyWithCommand -Path HKCR:\Directory\ContextMenus
289317
Set-RegistryKeyWithCommand -Path HKCR:\SOFTWARE\Classes\Directory\ContextMenus

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ The shortcuts will open desired shell in the current location, e.g. for Windows
1010

1111

1212
# Main features
13-
- Shortcut installation/removal for Windows PowerShell, Windows Terminal, CMD
13+
- Shortcut installation/removal for Windows PowerShell, Windows Terminal, CMD, PowerShell Core, Bash
1414
- Open here with non-elevated privileges shortcut.
1515
- Open here with elevated privileges shortcut.
16+
- Shortcut availability on **directory, drive, directory background, user's desktop**.
1617
- Default setting for easy-to-use.
1718
- Fully customizable shortcut names.
18-
- Shortcut availability on **directory, drive, directory background, user's desktop**.
19+
- Fully customizable shortcut icon.
20+
- Capability of showing the shortcut only if the SHIFT key is pressed.
1921
- Rollback of all shell modifications.
2022
- Works offline.
21-
- Well documented
23+
- Well documented.
2224

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

73+
For the default EXE icons as the shortcut icons, use `-UseExeIcon`:
74+
```powershell
75+
Set-OpenHereShortcut -ShortcutType:WindowsTerminal -UseExeIcon
76+
```
77+
78+
To show the Open Here shortcut only if the SHIFT key is pressed and the right mouse button is clicked, use `-UseShift`:
79+
```powershell
80+
Set-OpenHereShortcut -ShortcutType:WindowsTerminal -UseShift
81+
```
82+
7183
For more examples, type:
7284
```powershell
7385
Get-Help Set-OpenHereShortcut -Examples
@@ -83,12 +95,15 @@ Yes, see the section [Planned features.](https://github.com/KUTlime/PowerShell-O
8395
### Can I customize the shortcut icon?
8496
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.
8597

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

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

104+
### Windows Command Prompt icon looks weird when Windows Black theme is turn on. What should I do?
105+
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.
106+
92107
# Links
93108
[OpenHere module at PowerShell Gallery](https://www.powershellgallery.com/packages/OpenHere)
94109

0 commit comments

Comments
 (0)