Files
PowerShell/docs/cd-repos.md
Markus Fleschutz d8690419ea Updated the manuals
2025-06-22 10:38:33 +02:00

2.2 KiB

The cd-repos.ps1 Script

This PowerShell script changes the working directory to the folder for Git repositories.

Parameters

/Repos/PowerShell/scripts/cd-repos.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

Example

PS> ./cd-repos.ps1
📂C:\Repos with 33 folders entered.

Notes

Author: Markus Fleschutz | License: CC0

https://github.com/fleschutz/PowerShell

Script Content

<#
.SYNOPSIS
	Sets the working dir to the repos folder
.DESCRIPTION
	This PowerShell script changes the working directory to the folder for Git repositories.
.EXAMPLE
	PS> ./cd-repos.ps1
	📂C:\Repos with 33 folders entered.
.LINK
	https://github.com/fleschutz/PowerShell
.NOTES
	Author: Markus Fleschutz | License: CC0
#>

try {
	if (Test-Path "~/Repos"              -pathType container) { $path = "~/Repos"
	} elseif (Test-Path "~/repos"        -pathType container) { $path = "~/repos"
	} elseif (Test-Path "~/Repositories" -pathType container) { $path = "~/Repositories"
	} elseif (Test-Path "~/repositories" -pathType container) { $path = "~/repositories"
	} elseif (Test-Path "/Repos"         -pathType container) { $path = "/Repos"
	} elseif (Test-Path "/repos"         -pathType container) { $path = "/repos"
	} elseif (Test-Path "/Repositories"  -pathType container) { $path = "/Repositories"
	} elseif (Test-Path "/repositories"  -pathType container) { $path = "/repositories"
	} elseif (Test-Path "~/source/repos" -pathType container) { $path = "~/source/repos" # Visual Studio default
	} elseif (Test-Path "D:/Repos"	     -pathType container) { $path = "D:/Repos"       # second HDD
	} else { throw "Found no folder for Git repositories (in home or root directory) - Please create one." }
	$path = Resolve-Path $path
	Set-Location "$path"
	$folders = Get-ChildItem $path -attributes Directory
	"📂$path with $($folders.Count) folders entered."
	exit 0 # success
} catch {
	"⚠️ Error: $($Error[0])"
	exit 1
}

(page generated by convert-ps2md.ps1 as of 06/22/2025 10:37:34)