Enjoying Switches in Personal Powershell

The concern is documenting my recent enjoyment of switching for personal use when I just run

shp com.acme-prod1 c

… from anywhere and this pulls the recent updates from the acme repo + immediately opens a config file I want to check

1. backstory

  • I was listening to programmers saying “don’t do switching”
  • But I realized this is advice starts to pay off at the certain level of complexity
  • In my personal use of PowerShell, I use lots of procedures where I pass a letter of the alphabet that is suggestive of the name of the feature I want to use and it does it
  • take for example this go-ToRepo function living in my $profile
  • and I am using all of them and it (I believe) reads well (sorry for the cmdlet aliases)


# the concern is pulling recent updates from a repo + doing a required action as per the feature flag
function go-toRepo ($repoString, $featureFlag) {
$repostring = $repoString -replace "-.*", ""
$configFile = ".\jobs\config.yml.tmpl"
$redShiftFile = ".\jobs\enriched_redshift.json.tmpl"
$scheduleFolder = ".\schedules"
$repoFolder = "C:\Users\Admin\repos\"
if (Test-Path "$repoFolder\*$repoString*\") {
pushd "$repoFolder\*$repoString*\"
git pull
switch ($featureFlag) {
"b" { gc $configFile | sls "buckets:" -Context 15; Break }
"c" { ii $configFile; Break }
"r" { ii $redshiftFile; Break }
"s" { dir $scheduleFolder | gc; Break }
else { Write-Host "was not cloned yet" -ForegroundColor cyan }
# within $profile
Set-Alias shp go-toRepo

today I learnt… | as a support eng of the wonderful Snowplow Analytics, expect everything around modern (postmodern?) business intelligence

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store