From 84dc9c5f0ceea88b02a0fe3ee5ab229d8207fcb3 Mon Sep 17 00:00:00 2001 From: Jack Bennett Date: Wed, 25 Mar 2015 14:27:56 +0000 Subject: [PATCH] Helper function using powershell to register the cmder context menu Function must be run as an administrator since we're touching the registry. A neat by product is that users can now re-run this command and set custom icons. I'm not sure what the `%V` command does but it's not opening in the targeted folder as yet. The output is a little ugly at rpesent. --- scripts/utils.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index 04cb8cd..8657bf6 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -65,3 +65,32 @@ function Cleanup-Git () { $gitdir = '/vendor/msysgit/libexec/git-core/' Get-Childitem $gitdir -Exclude git.exe | Where-Object{!($_.PSIsContainer)} | Foreach-Object { Remove-Item $_.FullName } } + +function Register-Cmder(){ + [CmdletBinding()] + Param + ( + # Text for the context menu item. + $MenuText = "Cmder Here" + + , # Defaults to the current cmder directory when run from cmder. + $PathToExe = (Join-Path $env:CMDER_ROOT "cmder.exe") + + , # Commands the context menu will execute. + $Command = "%V" + + , # Defaults to the icons folder in the cmder package. + $icon = (Split-Path $PathToExe | join-path -ChildPath 'icons/cmder.ico') + ) + Begin + { + New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT + } + Process + { + New-Item -Path "HKCR:\Directory\Shell\Cmder" -Force -Value $MenuText + New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "Icon" -Value `"$icon`" + New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "NoWorkingDirectory" + New-Item -Path "HKCR:\Directory\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" " + } +}