Update cd-docs.ps1

This commit is contained in:
Markus Fleschutz 2022-02-25 09:23:38 +01:00
parent 6c03238aa9
commit 25fed61829

View File

@ -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))"