From 8f41760f3e6f1a8ac41231a62fd1e81f21eec86a Mon Sep 17 00:00:00 2001 From: Oussama Delassi <1280129+delassiops@users.noreply.github.com> Date: Mon, 21 Mar 2022 06:32:36 +0100 Subject: [PATCH] pwsh: add context menu (explorer, file) (#3411) * pwsh: add context menu (explorer, file) * pwsh: fix regedit script line ending * pwsh: rename to powershell core, rewrite post_install script * change regedit path from powershell7 to powershellcore as a name Co-authored-by: Gitea --- bucket/pwsh.json | 16 ++++++++ scripts/pwsh/install-explorer-context.reg | 41 +++++++++++++++++++++ scripts/pwsh/install-file-context.reg | 8 ++++ scripts/pwsh/uninstall-explorer-context.reg | 11 ++++++ scripts/pwsh/uninstall-file-context.reg | 4 ++ 5 files changed, 80 insertions(+) create mode 100644 scripts/pwsh/install-explorer-context.reg create mode 100644 scripts/pwsh/install-file-context.reg create mode 100644 scripts/pwsh/uninstall-explorer-context.reg create mode 100644 scripts/pwsh/uninstall-file-context.reg diff --git a/bucket/pwsh.json b/bucket/pwsh.json index 69b3b4a5cb..8d3f94bd99 100644 --- a/bucket/pwsh.json +++ b/bucket/pwsh.json @@ -3,6 +3,10 @@ "description": "Cross-platform automation and configuration tool/framework, known as Powershell Core, that works well with existing tools and is optimized for dealing with structured data.", "homepage": "https://github.com/PowerShell/PowerShell", "license": "MIT", + "notes": [ + "Add PowerShell Core as a explorer context menu by running: '$dir\\install-explorer-context.reg'", + "For file context menu, run '$dir\\install-file-context.reg'" + ], "architecture": { "64bit": { "url": "https://github.com/PowerShell/PowerShell/releases/download/v7.2.2/PowerShell-7.2.2-win-x64.zip", @@ -18,6 +22,18 @@ " if (!(Test-Path \"$persist_dir\\$_\")) { New-Item \"$dir\\$_\" | Out-Null }", "}" ], + "post_install": [ + "if ($architecture -eq '32bit') { $pwshArch = 'x86' } else { $pwshArch = 'x64' }", + "$pwshPath = \"$dir\\pwsh.exe\".Replace('\\', '\\\\')", + "'install-explorer-context', 'uninstall-explorer-context', 'install-file-context' , 'uninstall-file-context' | ForEach-Object {", + " if (Test-Path \"$bucketsdir\\main\\scripts\\pwsh\\$_.reg\") {", + " $content = (Get-Content \"$bucketsdir\\main\\scripts\\pwsh\\$_.reg\").Replace('$pwshPath', $pwshPath)", + " $content = $content.Replace('$pwshArch', $pwshArch)", + " if ($global) { $content = $content.Replace('HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE') }", + " Set-Content \"$dir\\$_.reg\" $content -Encoding Ascii -Force", + " }", + "}" + ], "bin": "pwsh.exe", "shortcuts": [ [ diff --git a/scripts/pwsh/install-explorer-context.reg b/scripts/pwsh/install-explorer-context.reg new file mode 100644 index 0000000000..ba5b06edef --- /dev/null +++ b/scripts/pwsh/install-explorer-context.reg @@ -0,0 +1,41 @@ +Windows Registry Editor Version 5.00 + +[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\PowerShellCore$pwshArch] +"ExtendedSubCommandsKey"="Directory\\ContextMenus\\PowerShellCore$pwshArch" +"MUIVerb"="&PowerShell Core" +"Icon"="$pwshPath" + +[HKEY_CURRENT_USER\Software\Classes\Drive\shell\PowerShellCore$pwshArch] +"MUIVerb"="&PowerShell Core" +"Icon"="$pwshPath" +"ExtendedSubCommandsKey"="Directory\\ContextMenus\\PowerShellCore$pwshArch" + +[HKEY_CURRENT_USER\Software\Classes\DesktopBackground\Shell\PowerShellCore$pwshArch] +"MUIVerb"="&PowerShell Core" +"Icon"="$pwshPath" +"ExtendedSubCommandsKey"="Directory\\ContextMenus\\PowerShellCore$pwshArch" + +[HKEY_CURRENT_USER\Software\Classes\Directory\shell\PowerShellCore$pwshArch] +"MUIVerb"="&PowerShell Core" +"Icon"="$pwshPath" +"ExtendedSubCommandsKey"="Directory\\ContextMenus\\PowerShellCore$pwshArch" + +[HKEY_CURRENT_USER\Software\Classes\LibraryFolder\background\shell\PowerShellCore$pwshArch] +"MUIVerb"="&PowerShell Core" +"Icon"="$pwshPath" +"ExtendedSubCommandsKey"="Directory\\ContextMenus\\PowerShellCore$pwshArch" + +[HKEY_CLASSES_ROOT\Directory\ContextMenus\PowerShellCore$pwshArch\shell\openpwsh] +"MUIVerb"="Open &here" +"Icon"="$pwshPath" + +[HKEY_CURRENT_USER\Software\Classes\Directory\ContextMenus\PowerShellCore$pwshArch\shell\openpwsh\command] +@="$pwshPath -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory \"%V!\" -Command \"$host.UI.RawUI.WindowTitle = 'PowerShell Core ($pwshArch)'\"" + +[HKEY_CURRENT_USER\Software\Classes\Directory\ContextMenus\PowerShellCore$pwshArch\shell\runas] +"MUIVerb"="Open here as &Administrator" +"Icon"="$pwshPath" +"HasLUAShield"="" + +[HKEY_CURRENT_USER\Software\Classes\Directory\ContextMenus\PowerShellCore$pwshArch\shell\runas\command] +@="$pwshPath -NoExit -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory \"%V!\" -Command \"$host.UI.RawUI.WindowTitle = 'PowerShell Core ($pwshArch)'\"" diff --git a/scripts/pwsh/install-file-context.reg b/scripts/pwsh/install-file-context.reg new file mode 100644 index 0000000000..d065582560 --- /dev/null +++ b/scripts/pwsh/install-file-context.reg @@ -0,0 +1,8 @@ +Windows Registry Editor Version 5.00 + +[HKEY_CURRENT_USER\Software\Classes\*\shell\PowerShellCore$pwshArch] +"Icon"="$pwshPath" +"MUIVerb"="Run with PowerShell Core" + +[HKEY_CURRENT_USER\Software\Classes\*\shell\PowerShellCore$pwshArch\Command] +@="$pwshPath -Command \"$host.UI.RawUI.WindowTitle = 'PowerShell Core ($pwshArch)'; if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\"" diff --git a/scripts/pwsh/uninstall-explorer-context.reg b/scripts/pwsh/uninstall-explorer-context.reg new file mode 100644 index 0000000000..aaf138a7c9 --- /dev/null +++ b/scripts/pwsh/uninstall-explorer-context.reg @@ -0,0 +1,11 @@ +Windows Registry Editor Version 5.00 + +[-HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\PowerShellCore$pwshArch] +[-HKEY_CURRENT_USER\Software\Classes\Drive\shell\PowerShellCore$pwshArch] +[-HKEY_CURRENT_USER\Software\Classes\DesktopBackground\Shell\PowerShellCore$pwshArch] +[-HKEY_CURRENT_USER\Software\Classes\Directory\shell\PowerShellCore$pwshArch] +[-HKEY_CURRENT_USER\Software\Classes\LibraryFolder\background\shell\PowerShellCore$pwshArch] +[-HKEY_CURRENT_USER\Software\Classes\Directory\ContextMenus\PowerShellCore$pwshArch\shell\openpwsh] +[-HKEY_CURRENT_USER\Software\Classes\Directory\ContextMenus\PowerShellCore$pwshArch\shell\openpwsh\command] +[-HKEY_CURRENT_USER\Software\Classes\Directory\ContextMenus\PowerShellCore$pwshArch\shell\runas] +[-HKEY_CURRENT_USER\Software\Classes\Directory\ContextMenus\PowerShellCore$pwshArch\shell\runas\command] diff --git a/scripts/pwsh/uninstall-file-context.reg b/scripts/pwsh/uninstall-file-context.reg new file mode 100644 index 0000000000..434276745f --- /dev/null +++ b/scripts/pwsh/uninstall-file-context.reg @@ -0,0 +1,4 @@ +Windows Registry Editor Version 5.00 + +[-HKEY_CURRENT_USER\Software\Classes\*\shell\PowerShellCore$pwshArch] +[-HKEY_CURRENT_USER\Software\Classes\*\shell\PowerShellCore$pwshArch\Command]