I have a habit of keeping a \Dev directory on any machine I do any significant development on. And of course, I’m never without PowerShell. So I drop a Startup.ps1 file in that Dev directory, and in my Profile.ps1 I start looking for it on C:, D:, E:, etc.
I also carry around a bunch of things in a “bin” folder that I tend to always want handy; things like:
- cdburn/dvdburn (probably disappear once I’m consolidated on Win7/Win2k8 R2)
- zip/unzip/gzip/gunzip/unrar
- Reflector
- Notepad2
- WindowClippings
- cpc/tfc
The location of the dev files vary from machine to machine, and until today, I’d been keeping separate copies of that Startup.ps1. I really wanted to keep everything sync’d up with Windows Live Sync, but in order to do that, I needed to make my Startup.ps1 file portable.
This is the top of my Startup.ps1 file, which figures out where it’s running from and automatically registers the Notepad2 shell extension if it’s never been registered:
$dev = (split-path $MyInvocation.MyCommand.Path)
if ((test-path "$dev\bin\notepad2.exe") -eq $true) {
set-content env:\EDITOR "$dev\bin\notepad2.exe"
push-location -literalPath "HKLM:\Software\Classes\`*\shell"
new-item -type directory -path Notepad2 -ErrorAction:SilentlyContinue | out-null
new-item -type directory -path Notepad2\command -ErrorAction:SilentlyContinue | out-null
set-itemproperty -path Notepad2\command -name "(default)" -value "$dev\bin\notepad2.exe `"%1`""
pop-location
}
append-path $dev\bin
The append-path command there is one my standard cadre of scripts that I always take with me:
$local:command_usage =
"usage: append-path path-to-be-added
"
if ($args.length -lt 1) { return ($command_usage) }
$local:oldPath = get-content Env:\Path
$local:newPath = $local:oldPath + ";" + $args
set-content Env:\Path $local:newPath