From 25fed6182943aaa2c3f50a01486340b95c76b386 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Fri, 25 Feb 2022 09:23:38 +0100 Subject: [PATCH] Update cd-docs.ps1 --- Scripts/cd-docs.ps1 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Scripts/cd-docs.ps1 b/Scripts/cd-docs.ps1 index 799c80de..57970014 100755 --- a/Scripts/cd-docs.ps1 +++ b/Scripts/cd-docs.ps1 @@ -1,11 +1,11 @@ <# .SYNOPSIS - Sets the working directory to the user's documents folder + Sets the working directory to the documents folder .DESCRIPTION - This PowerShell script changes the working directory to the user's documents folder. + This PowerShell script changes the working directory to the documents folder. .EXAMPLE PS> ./cd-docs - 📂/home/markus/Documents + 📂C:\Users\Joe\Documents .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -13,12 +13,16 @@ #> try { - $TargetDir = resolve-path "$HOME/Documents" - if (-not(test-path "$TargetDir" -pathType container)) { - throw "Documents folder at 📂$TargetDir doesn't exist (yet)" + if ($IsLinux) { + $DocsFolder = Resolve-Path "$HOME/Documents" + } else { + $DocsFolder = [Environment]::GetFolderPath('MyDocuments') } - set-location "$TargetDir" - "📂$TargetDir" + if (-not(Test-Path "$DocsFolder" -pathType container)) { + throw "Documents folder at 📂$DocsFolder doesn't exist (yet)" + } + set-location "$DocsFolder" + "📂$DocsFolder" exit 0 # success } catch { "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"