From 51b541e0de7cfd0a4f2a1b1eec0699207ff61af6 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 9 Jul 2025 14:19:53 +0200 Subject: [PATCH] Updated the cd-*.ps1 scripts --- scripts/cd-autostart.ps1 | 2 ++ scripts/cd-crashdumps.ps1 | 2 ++ scripts/cd-desktop.ps1 | 2 ++ scripts/cd-dropbox.ps1 | 2 ++ scripts/cd-etc.ps1 | 2 ++ scripts/cd-jenkins.ps1 | 4 +++- scripts/cd-logs.ps1 | 10 ++++++---- scripts/cd-music.ps1 | 4 +++- scripts/cd-nextcloud.ps1 | 10 ++++++---- scripts/cd-onedrive.ps1 | 4 +++- scripts/cd-pics.ps1 | 6 ++++-- scripts/cd-public.ps1 | 6 ++++-- scripts/cd-recent.ps1 | 17 +++++++++-------- scripts/cd-recycle-bin.ps1 | 6 ++++-- scripts/cd-repo.ps1 | 4 ++-- scripts/cd-repos.ps1 | 4 ++-- scripts/cd-root.ps1 | 4 +++- scripts/cd-screenshots.ps1 | 4 +++- scripts/cd-scripts.ps1 | 6 ++++-- scripts/cd-ssh.ps1 | 4 +++- scripts/cd-sync.ps1 | 4 +++- scripts/cd-temp.ps1 | 6 +++--- scripts/cd-templates.ps1 | 4 +++- scripts/cd-trash.ps1 | 6 +++--- scripts/cd-up.ps1 | 8 +++++--- scripts/cd-up2.ps1 | 10 ++++++---- scripts/cd-up3.ps1 | 10 ++++++---- scripts/cd-up4.ps1 | 10 ++++++---- scripts/cd-users.ps1 | 9 +++++---- scripts/cd-videos.ps1 | 10 ++++++---- 30 files changed, 115 insertions(+), 65 deletions(-) diff --git a/scripts/cd-autostart.ps1 b/scripts/cd-autostart.ps1 index 6f6cbd7e..0517cfdc 100755 --- a/scripts/cd-autostart.ps1 +++ b/scripts/cd-autostart.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = Resolve-Path "~/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup" if (-not(Test-Path "$path" -pathType container)) { diff --git a/scripts/cd-crashdumps.ps1 b/scripts/cd-crashdumps.ps1 index 92babdc3..ce90e2fe 100755 --- a/scripts/cd-crashdumps.ps1 +++ b/scripts/cd-crashdumps.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux) { throw "Sorry, Windows only" } diff --git a/scripts/cd-desktop.ps1 b/scripts/cd-desktop.ps1 index 563f3825..676fd7a8 100755 --- a/scripts/cd-desktop.ps1 +++ b/scripts/cd-desktop.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux -or $IsMacOS) { if (-not(Test-Path "~/Desktop" -pathType container)) { diff --git a/scripts/cd-dropbox.ps1 b/scripts/cd-dropbox.ps1 index 9ca3274c..6a31203c 100755 --- a/scripts/cd-dropbox.ps1 +++ b/scripts/cd-dropbox.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if (-not(Test-Path "~/Dropbox" -pathType container)) { throw "No 'Dropbox' folder in your home directory - is Dropbox installed?" diff --git a/scripts/cd-etc.ps1 b/scripts/cd-etc.ps1 index 0135d36b..ee086c6d 100755 --- a/scripts/cd-etc.ps1 +++ b/scripts/cd-etc.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux -or $IsMacOS) { $path = "/etc" diff --git a/scripts/cd-jenkins.ps1 b/scripts/cd-jenkins.ps1 index 3514eb5c..c9a05c74 100755 --- a/scripts/cd-jenkins.ps1 +++ b/scripts/cd-jenkins.ps1 @@ -4,7 +4,7 @@ .DESCRIPTION This PowerShell script changes the working directory to the Jenkins home directory. .EXAMPLE - PS> ./cd-jenkins + PS> ./cd-jenkins.ps1 📂C:\Users\Markus\.jenkins entered (has 2 files and 21 folders) .LINK https://github.com/fleschutz/PowerShell @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if (Test-Path "~/.jenkins" -pathType container) { $path = "~/.jenkins" diff --git a/scripts/cd-logs.ps1 b/scripts/cd-logs.ps1 index 31a5e702..33022e88 100755 --- a/scripts/cd-logs.ps1 +++ b/scripts/cd-logs.ps1 @@ -4,14 +4,16 @@ .DESCRIPTION This PowerShell script changes the current working directory to the logs directory. .EXAMPLE - PS> ./cd-logs - 📂/var/logs entered (has 3 files and 2 subfolders) + PS> ./cd-logs.ps1 + 📂/var/logs with 3 files and 2 folders entered. .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + function GetLogsDir { if ($IsLinux -or $IsMacOS) { return "/var/logs" } $WinDir = [System.Environment]::GetFolderPath('Windows') @@ -23,9 +25,9 @@ try { Set-Location "$path" $files = Get-ChildItem $path -attributes !Directory $folders = Get-ChildItem $path -attributes Directory - "📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)" + "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-music.ps1 b/scripts/cd-music.ps1 index 78d5592c..5fbf410b 100755 --- a/scripts/cd-music.ps1 +++ b/scripts/cd-music.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux) { if (-not(Test-Path "~/Music/" -pathType container)) { @@ -30,6 +32,6 @@ try { "📂$path with $($folders.Count) folders and $($files.Count) files entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-nextcloud.ps1 b/scripts/cd-nextcloud.ps1 index 1a78e2f2..d46d2171 100755 --- a/scripts/cd-nextcloud.ps1 +++ b/scripts/cd-nextcloud.ps1 @@ -4,14 +4,16 @@ .DESCRIPTION This PowerShell script changes the working directory to the user's NextCloud folder. .EXAMPLE - PS> ./cd-nextcloud - 📂C:\Users\Markus\NextCloud entered (has 2 files and 0 folders) + PS> ./cd-nextcloud.ps1 + 📂C:\Users\Markus\NextCloud with 2 files and 0 folders entered. .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if (-not(Test-Path "~/NextCloud" -pathType container)) { throw "No 'NextCloud' folder in your home directory - is NextCloud installed?" @@ -20,9 +22,9 @@ try { Set-Location "$path" $files = Get-ChildItem $path -attributes !Directory $folders = Get-ChildItem $path -attributes Directory - "📂$path entered (has $($files.Count) files and $($folders.Count) folders)" + "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-onedrive.ps1 b/scripts/cd-onedrive.ps1 index eebdacb8..f0e231bc 100755 --- a/scripts/cd-onedrive.ps1 +++ b/scripts/cd-onedrive.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if (-not(Test-Path "~/OneDrive" -pathType container)) { throw "No 'OneDrive' folder in your home directory - is OneDrive installed?" @@ -23,6 +25,6 @@ try { "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-pics.ps1 b/scripts/cd-pics.ps1 index ff98c6b0..3dcfecee 100755 --- a/scripts/cd-pics.ps1 +++ b/scripts/cd-pics.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Sets the working dir to the user's pictures folder .DESCRIPTION - This PowerShell script sets the current working directory to the user's pictures folder. + This PowerShell script changes the current working directory to the user's pictures folder. .EXAMPLE PS> ./cd-pics.ps1 📂C:\Users\Markus\Pictures with 7 files and 0 folders entered. @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux) { if (-not(Test-Path "~/Pictures" -pathType container)) { @@ -30,6 +32,6 @@ try { "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-public.ps1 b/scripts/cd-public.ps1 index 80f6b3bb..315e3561 100755 --- a/scripts/cd-public.ps1 +++ b/scripts/cd-public.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Sets the working dir to the Public folder .DESCRIPTION - This PowerShell script sets the current working directory to the Public folder. + This PowerShell script changes the current working directory to the Public folder. .EXAMPLE PS> ./cd-public.ps1 📂C:\Users\Public with 2 files and 3 folders entered. @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux) { if (-not(Test-Path "~/Public" -pathType container)) { @@ -30,6 +32,6 @@ try { "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-recent.ps1 b/scripts/cd-recent.ps1 index 84093498..a6f38aa3 100755 --- a/scripts/cd-recent.ps1 +++ b/scripts/cd-recent.ps1 @@ -2,27 +2,28 @@ .SYNOPSIS Sets the working directory to the 'recent' folder .DESCRIPTION - This PowerShell script changes the working directory to the 'recent' folder. + This PowerShell script changes the current working directory to the 'recent' folder. .EXAMPLE - PS> ./cd-recent - 📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent entered (has 2 files and 3 subfolders) + PS> ./cd-recent.ps1 + 📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent with 2 files and 3 folders entered. .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = [Environment]::GetFolderPath('Recent') - if (-not(Test-Path "$path" -pathType container)) { - throw "No recent folder at $path" - } + if (-not(Test-Path "$path" -pathType container)) { throw "No recent folder at $path" } + Set-Location "$path" $files = Get-ChildItem $path -attributes !Directory $folders = Get-ChildItem $path -attributes Directory - "📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)" + "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-recycle-bin.ps1 b/scripts/cd-recycle-bin.ps1 index 1d00a4bd..e135ec67 100755 --- a/scripts/cd-recycle-bin.ps1 +++ b/scripts/cd-recycle-bin.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Sets the working dir to the recycle bin folder .DESCRIPTION - This PowerShell script changes the working directory to the user's recycle bin folder. + This PowerShell script changes the current working directory to the user's recycle bin folder. .EXAMPLE PS> ./cd-recycle-bin.ps1 📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 with 2 files and 0 folders entered. @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + function GetCurrentUserSID { [CmdletBinding()] param() Add-Type -AssemblyName System.DirectoryServices.AccountManagement return ([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value @@ -33,6 +35,6 @@ try { "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-repo.ps1 b/scripts/cd-repo.ps1 index 117093e7..42637c44 100755 --- a/scripts/cd-repo.ps1 +++ b/scripts/cd-repo.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Sets the working directory to a repo .DESCRIPTION - This PowerShell script changes the working directory to the given local Git repository. + This PowerShell script changes the current working directory to the given local Git repository. .PARAMETER folderName Specifies the folder name of the Git repository .EXAMPLE @@ -43,6 +43,6 @@ try { & git status --branch --short exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-repos.ps1 b/scripts/cd-repos.ps1 index c69af1d6..efaa4a49 100755 --- a/scripts/cd-repos.ps1 +++ b/scripts/cd-repos.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Sets the working dir to the repos folder .DESCRIPTION - This PowerShell script changes the working directory to the folder for Git repositories. + This PowerShell script changes the current working directory to the folder for Git repositories. .EXAMPLE PS> ./cd-repos.ps1 📂C:\Repos with 33 folders entered. @@ -32,6 +32,6 @@ try { "📂$path with $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-root.ps1 b/scripts/cd-root.ps1 index 37bf648e..8279401b 100755 --- a/scripts/cd-root.ps1 +++ b/scripts/cd-root.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux -or $IsMacOS) { $path = "/" } else { $path = "C:\" } Set-Location "$path" @@ -20,6 +22,6 @@ try { "📂$path with $($folders.Count) folders and $($files.Count) files entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-screenshots.ps1 b/scripts/cd-screenshots.ps1 index b73184be..b16ce6df 100755 --- a/scripts/cd-screenshots.ps1 +++ b/scripts/cd-screenshots.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + function GetScreenshotsFolder { if ($IsLinux) { if (-not(Test-Path "~/Pictures" -pathType container)) { throw "No 'Pictures' folder in your home directory yet" } @@ -33,6 +35,6 @@ try { "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-scripts.ps1 b/scripts/cd-scripts.ps1 index 1980fe5f..fba2f6a9 100755 --- a/scripts/cd-scripts.ps1 +++ b/scripts/cd-scripts.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Sets the working directory to the PowerShell scripts folder .DESCRIPTION - This PowerShell script changes the working directory to the PowerShell scripts folder. + This PowerShell script changes the currrent working directory to the PowerShell scripts folder. .EXAMPLE PS> ./cd-scripts.ps1 📂C:\Repos\PowerShell\scripts with 655 scripts entered. @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = Resolve-Path "$PSScriptRoot" if (-not(Test-Path "$path" -pathType container)) { throw "No scripts folder at: $path" } @@ -20,6 +22,6 @@ try { "📂$path with $($files.Count) scripts entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-ssh.ps1 b/scripts/cd-ssh.ps1 index 4d812885..2de3f7f4 100755 --- a/scripts/cd-ssh.ps1 +++ b/scripts/cd-ssh.ps1 @@ -12,10 +12,12 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = "~/.ssh" if (-not(Test-Path "$path" -pathType container)) { - throw "Your home directory has no '.ssh' folder yet - Please install SSH." + throw "No '.ssh' folder in your home directory yet - Please install SSH." } $path = Resolve-Path "$path" Set-Location "$path" diff --git a/scripts/cd-sync.ps1 b/scripts/cd-sync.ps1 index 2f5b0512..7c0b39d2 100755 --- a/scripts/cd-sync.ps1 +++ b/scripts/cd-sync.ps1 @@ -12,9 +12,11 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if (-not(Test-Path "~/Sync" -pathType container)) { - throw "Your home directory has no 'Sync' folder yet - Please install Syncthing." + throw "No 'Sync' folder in your home directory yet - Please install Syncthing." } $path = Resolve-Path "~/Sync" Set-Location "$path" diff --git a/scripts/cd-temp.ps1 b/scripts/cd-temp.ps1 index 66f3fb76..adf4ac6a 100755 --- a/scripts/cd-temp.ps1 +++ b/scripts/cd-temp.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + function GetTempDir { if ("$env:TEMP" -ne "") { return "$env:TEMP" } if ("$env:TMP" -ne "") { return "$env:TMP" } @@ -21,9 +23,7 @@ function GetTempDir { try { $path = GetTempDir - if (-not(Test-Path "$path" -pathType container)) { throw - "No temporary folder at: $path" - } + if (-not(Test-Path "$path" -pathType container)) { throw "No temporary folder at: $path" } Set-Location "$path" $files = Get-ChildItem $path -attributes !Directory $folders = Get-ChildItem $path -attributes Directory diff --git a/scripts/cd-templates.ps1 b/scripts/cd-templates.ps1 index aff4de21..1bc62007 100755 --- a/scripts/cd-templates.ps1 +++ b/scripts/cd-templates.ps1 @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux) { if (-not(Test-Path "~/Templates" -pathType container)) { @@ -30,6 +32,6 @@ try { "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-trash.ps1 b/scripts/cd-trash.ps1 index eef88a26..91737aed 100755 --- a/scripts/cd-trash.ps1 +++ b/scripts/cd-trash.ps1 @@ -2,9 +2,9 @@ .SYNOPSIS Sets the working dir to the trash folder .DESCRIPTION - This PowerShell script changes the working directory to the user's trash folder. + This PowerShell script changes the current working directory to the user's trash folder. .EXAMPLE - PS> ./cd-trash + PS> ./cd-trash.ps1 📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 with 4 files and 0 folders entered. .LINK https://github.com/fleschutz/PowerShell @@ -35,6 +35,6 @@ try { "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-up.ps1 b/scripts/cd-up.ps1 index 62752822..305ca1d4 100755 --- a/scripts/cd-up.ps1 +++ b/scripts/cd-up.ps1 @@ -2,9 +2,9 @@ .SYNOPSIS Sets the working directory to one level up .DESCRIPTION - This PowerShell script changes the working directory to one directory level up. + This PowerShell script changes the current working directory to one directory level up. .EXAMPLE - PS> .\cd-up + PS> .\cd-up.ps1 📂C:\Users .LINK https://github.com/fleschutz/PowerShell @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = Resolve-Path ".." if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" } @@ -19,6 +21,6 @@ try { "📂$path" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-up2.ps1 b/scripts/cd-up2.ps1 index 77a9f4bb..3095b5a4 100755 --- a/scripts/cd-up2.ps1 +++ b/scripts/cd-up2.ps1 @@ -1,10 +1,10 @@ <# .SYNOPSIS - Sets the working directory to two directory levels up + Sets the working directory 2 directory levels up .DESCRIPTION - This PowerShell script changes the working directory to two directory level up. + This PowerShell script changes the current working directory to two directory level up. .EXAMPLE - PS> ./cd-up2 + PS> ./cd-up2.ps1 📂C:\ .LINK https://github.com/fleschutz/PowerShell @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = Resolve-Path "../.." if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" } @@ -19,6 +21,6 @@ try { "📂$path" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-up3.ps1 b/scripts/cd-up3.ps1 index 9dabb01c..9779b9d9 100755 --- a/scripts/cd-up3.ps1 +++ b/scripts/cd-up3.ps1 @@ -1,10 +1,10 @@ <# .SYNOPSIS - Sets the working directory to three directory levels up + Sets the working directory 3 directory levels up .DESCRIPTION - This PowerShell script changes the working directory to three directory levels up. + This PowerShell script changes the current working directory to three directory levels up. .EXAMPLE - PS> ./cd-up3 + PS> ./cd-up3.ps1 📂C:\ .LINK https://github.com/fleschutz/PowerShell @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = Resolve-Path "../../.." if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" } @@ -19,6 +21,6 @@ try { "📂$path" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-up4.ps1 b/scripts/cd-up4.ps1 index 81c658bc..6c185f86 100755 --- a/scripts/cd-up4.ps1 +++ b/scripts/cd-up4.ps1 @@ -1,10 +1,10 @@ <# .SYNOPSIS - Sets the working directory to four directory levels up + Sets the working directory 4 directory levels up .DESCRIPTION - This PowerShell script changes the working directory to four directory levels up. + This PowerShell script changes the current working directory to four directory levels up. .EXAMPLE - PS> ./cd-up4 + PS> ./cd-up4.ps1 📂C:\ .LINK https://github.com/fleschutz/PowerShell @@ -12,6 +12,8 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = Resolve-Path "../../../.." if (-not(Test-Path "$path" -pathType container)) { throw "Folder at 📂$path doesn't exist (yet)" } @@ -19,6 +21,6 @@ try { "📂$path" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-users.ps1 b/scripts/cd-users.ps1 index ae45f97d..41295323 100755 --- a/scripts/cd-users.ps1 +++ b/scripts/cd-users.ps1 @@ -12,16 +12,17 @@ Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { $path = Resolve-Path "~/.." - if (-not(Test-Path "$path" -pathType container)) { - throw "No users directory at: $path" - } + if (-not(Test-Path "$path" -pathType container)) { throw "No users directory at: $path" } + Set-Location "$path" $folders = Get-ChildItem $path -attributes Directory "📂$path with $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 } diff --git a/scripts/cd-videos.ps1 b/scripts/cd-videos.ps1 index 90be1ab7..da7d7d83 100755 --- a/scripts/cd-videos.ps1 +++ b/scripts/cd-videos.ps1 @@ -4,14 +4,16 @@ .DESCRIPTION This PowerShell script changes the working directory to the user's videos folder. .EXAMPLE - PS> ./cd-videos - 📂C:\Users\Markus\Videos entered (has 3 files and 0 subfolders) + PS> ./cd-videos.ps1 + 📂C:\Users\Markus\Videos with 3 files and 0 folders entered. .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> +#requires -version 5.1 + try { if ($IsLinux) { $path = Resolve-Path "~/Videos" @@ -24,9 +26,9 @@ try { Set-Location "$path" $files = Get-ChildItem $path -attributes !Directory $folders = Get-ChildItem $path -attributes Directory - "📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)" + "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0])" exit 1 }