From 7213c99d05dfa4f89db3a0386bdfe5c8f1e04e92 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Tue, 3 Jan 2023 12:02:18 +0100 Subject: [PATCH] Added cd-templates.ps1 --- Scripts/cd-templates.ps1 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Scripts/cd-templates.ps1 diff --git a/Scripts/cd-templates.ps1 b/Scripts/cd-templates.ps1 new file mode 100644 index 00000000..d5414c11 --- /dev/null +++ b/Scripts/cd-templates.ps1 @@ -0,0 +1,30 @@ +<# +.SYNOPSIS + Sets the working directory to the templates folder +.DESCRIPTION + This PowerShell script changes the working directory to the templates folder. +.EXAMPLE + PS> ./cd-templates + 📂/home/Markus/Templates +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +try { + if ($IsLinux) { + $Path = Resolve-Path "~/Templates" + } else { + $Path = [Environment]::GetFolderPath('CommonTemplates') + } + if (Test-Path "$Path" -pathType container) { + Set-Location "$Path" + "📂$Path" + exit 0 # success + } + throw "Templates folder at 📂$Path doesn't exist (yet)" +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +} \ No newline at end of file