Updated cd-repos.ps1 and new-symlink.ps1

This commit is contained in:
Markus Fleschutz 2025-01-08 15:51:28 +01:00
parent f1a20bc962
commit 9cf0ecacb3
2 changed files with 12 additions and 7 deletions

View File

@ -1,13 +1,13 @@
<#
.SYNOPSIS
Sets the working directory to the user's repos folder
Sets the working directory to the Git repos folder
.DESCRIPTION
This PowerShell script changes the working directory to the user's Git repositories folder.
This PowerShell script changes the working directory to the Git repositories folder.
.PARAMETER subpath
Specifies an additional relative subpath (optional)
.EXAMPLE
PS> ./cd-repos.ps1
📂C:\Users\Markus\Repos
📂C:\Repos
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -25,6 +25,10 @@ try {
$path = "~/source/repos/"
} elseif (Test-Path "/Repos/" -pathType Container) {
$path = "/Repos/"
} elseif (Test-Path "C:/Repos" -pathType Container) {
$path = "C:/Repos"
} elseif (Test-Path "C:/Repositories" -pathType Container) {
$path = "C:/Repositories"
} else {
throw "The folder for Git repositories doesn't exist (yet)"
}

View File

@ -4,12 +4,12 @@
.DESCRIPTION
This PowerShell script creates a new symbolic link file, linking to a target.
.PARAMETER symlink
Specifies the path to the new symlink file
Specifies the file path to the new symlink file
.PARAMETER target
Specifies the path to the target
Specifies the file path to the target
.EXAMPLE
PS> ./new-symlink.ps1 C:\User\Markus\Windows C:\Windows
New symlink file 'C:\User\Markus\Windows' created, linking to: C:\Windows
Created new symlink file 'C:\User\Markus\Windows', linking to: C:\Windows
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -23,8 +23,9 @@ try {
if ($target -eq "" ) { $target = Read-Host "Enter path to target" }
New-Item -path "$symlink" -itemType SymbolicLink -value "$target"
if ($lastExitCode -ne "0") { throw "Command 'New-Item' has failed" }
"New symlink file '$symlink' created, linking to: $target"
"Created new symlink file '$symlink', linking to: $target"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"