From 2a009f311fe9726c697e2a9fba5109fa9a18c93e Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 10 Oct 2024 14:40:19 +0200 Subject: [PATCH] Updated cd-repo.ps1 and cd-ssh.ps1 --- scripts/cd-repo.ps1 | 33 +++++++++++++++++---------------- scripts/cd-ssh.ps1 | 15 ++++++++------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/scripts/cd-repo.ps1 b/scripts/cd-repo.ps1 index 771c9fcf..942110f9 100755 --- a/scripts/cd-repo.ps1 +++ b/scripts/cd-repo.ps1 @@ -1,13 +1,13 @@ ๏ปฟ<# .SYNOPSIS - Sets the working directory to a repository + Sets the working directory to a repo .DESCRIPTION - This PowerShell script changes the working directory to a local Git repository. + This PowerShell script changes the working directory to the given local Git repository. .PARAMETER folderName - Specifies the Git repository's folder name + Specifies the folder name of the Git repository .EXAMPLE PS> ./cd-repo.ps1 rust - ๐Ÿ“‚C:\Repos\rust - current branch is: ## main ... origin/main + ๐Ÿ“‚C:\Repos\rust ยท on branch: ## main ... origin/main .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -19,25 +19,26 @@ param([string]$folderName = "") try { if ("$folderName" -eq "") { $folderName = Read-Host "Enter the Git repository's folder name" } - if (Test-Path "$HOME/Repos/" -pathType Container) { # try short name - $path = "$HOME/Repos/" - } elseif (Test-Path "$HOME/repos/" -pathType Container) { - $path = "$HOME/repos/" - } elseif (Test-Path "$HOME/Repositories/" -pathType Container) { # try long name - $path = "$HOME/Repositories/" - } elseif (Test-Path "$HOME/source/repos/" -pathType Container) { # try Visual Studio default - $path = "$HOME/source/repos/" - } elseif (Test-Path "/Repos/" -pathType Container) { + if (Test-Path "~/Repos/" -pathType container) { # try short name + $path = "~/Repos/" + } elseif (Test-Path "~/repos/" -pathType container) { + $path = "~/repos/" + } elseif (Test-Path "~/Repositories/" -pathType container) { # try long name + $path = "~/Repositories/" + } elseif (Test-Path "~/source/repos/" -pathType container) { # try Visual Studio default + $path = "~/source/repos/" + } elseif (Test-Path "/Repos/" -pathType container) { $path = "/Repos/" } else { throw "The folder for Git repositories doesn't exist (yet)" } - $path += $folderName - if (-not(Test-Path "$path" -pathType Container)) { throw "The path to ๐Ÿ“‚$path doesn't exist (yet)" } + $path += $folderName + if (-not(Test-Path "$path" -pathType container)) { throw "The path to ๐Ÿ“‚$path doesn't exist (yet)" } + $path = Resolve-Path "$path" Set-Location "$path" - Write-Host "๐Ÿ“‚$path - current branch is: " -noNewline + Write-Host "๐Ÿ“‚$path ยท on branch: " -noNewline & git status --short --branch --show-stash exit 0 # success } catch { diff --git a/scripts/cd-ssh.ps1 b/scripts/cd-ssh.ps1 index 7b653a6a..bde81a09 100755 --- a/scripts/cd-ssh.ps1 +++ b/scripts/cd-ssh.ps1 @@ -1,10 +1,10 @@ ๏ปฟ<# .SYNOPSIS - Sets the working directory to the user's SSH folder + Sets the working directory to the SSH folder .DESCRIPTION - This PowerShell script changes the working directory to the user's SSH folder. + This PowerShell script changes the working directory to the user's secure shell (SSH) folder. .EXAMPLE - PS> ./cd-ssh + PS> ./cd-ssh.ps1 ๐Ÿ“‚C:\Users\Markus\.ssh .LINK https://github.com/fleschutz/PowerShell @@ -13,12 +13,13 @@ #> try { - $Path = Resolve-Path "~/.ssh" - if (-not(Test-Path "$Path" -pathType container)) { throw "User's SSH folder at ๐Ÿ“‚$Path doesn't exist (yet)" } - Set-Location "$Path" + $path = "~/.ssh" + if (-not(Test-Path "$path" -pathType container)) { throw "Your secure shell (SSH) folder at ๐Ÿ“‚$path doesn't exist (yet)" } + $path = Resolve-Path "$path" + Set-Location "$path" "๐Ÿ“‚$Path" exit 0 # success } catch { - "โš ๏ธ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "โš ๏ธ Error: $($Error[0])" exit 1 }