From c35fcd8ea0311f9e7f4f74ca08d766ae6e7154b0 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 23 Apr 2025 13:22:05 +0200 Subject: [PATCH] Improved some cd-*.ps1 scripts --- scripts/cd-desktop.ps1 | 11 +++++++---- scripts/cd-docs.ps1 | 11 +++++++---- scripts/cd-downloads.ps1 | 2 +- scripts/cd-dropbox.ps1 | 12 +++++++----- scripts/cd-etc.ps1 | 8 +++++--- scripts/cd-fonts.ps1 | 6 ++++-- scripts/cd-home.ps1 | 6 +++--- scripts/cd-logs.ps1 | 8 +++++--- 8 files changed, 39 insertions(+), 25 deletions(-) diff --git a/scripts/cd-desktop.ps1 b/scripts/cd-desktop.ps1 index e36c9a15..017e34e3 100755 --- a/scripts/cd-desktop.ps1 +++ b/scripts/cd-desktop.ps1 @@ -13,13 +13,16 @@ #> try { - if ($IsLinux) { + if ($IsLinux -or $IsMacOS) { + if (-not(Test-Path "~/Desktop" -pathType container)) { + throw "No πŸ“‚Desktop folder in your home directory yet" + } $path = Resolve-Path "~/Desktop" } else { $path = [Environment]::GetFolderPath('DesktopDirectory') - } - if (-not(Test-Path "$path" -pathType container)) { - throw "No desktop folder at πŸ“‚$path" + if (-not(Test-Path "$path" -pathType container)) { + throw "No desktop folder at πŸ“‚$path yet" + } } Set-Location "$path" "πŸ“‚$path" diff --git a/scripts/cd-docs.ps1 b/scripts/cd-docs.ps1 index dfa88a1a..1e99115f 100755 --- a/scripts/cd-docs.ps1 +++ b/scripts/cd-docs.ps1 @@ -13,13 +13,16 @@ #> try { - if ($IsLinux) { + if ($IsLinux -or $IsMacOS) { + if (-not(Test-Path "~/Documents" -pathType container)) { + throw "No πŸ“‚Documents folder in your home directory yet" + } $path = Resolve-Path "~/Documents" } else { $path = [Environment]::GetFolderPath('MyDocuments') - } - if (-not(Test-Path "$path" -pathType container)) { - throw "No documents folder at πŸ“‚$path" + if (-not(Test-Path "$path" -pathType container)) { + throw "No documents folder at πŸ“‚$path yet" + } } Set-Location "$path" $files = Get-ChildItem $path -attributes !Directory diff --git a/scripts/cd-downloads.ps1 b/scripts/cd-downloads.ps1 index bb7839d4..acdbc1c3 100755 --- a/scripts/cd-downloads.ps1 +++ b/scripts/cd-downloads.ps1 @@ -15,7 +15,7 @@ try { if ($IsLinux -or $IsMacOS) { if (-not(Test-Path "~/Downloads" -pathType container)) { - throw "No downloads folder at ~/Downloads yet" + throw "No πŸ“‚Downloads folder in your home directory yet" } $path = Resolve-Path "~/Downloads" } else { diff --git a/scripts/cd-dropbox.ps1 b/scripts/cd-dropbox.ps1 index 8d0cab2d..0d515c10 100755 --- a/scripts/cd-dropbox.ps1 +++ b/scripts/cd-dropbox.ps1 @@ -5,7 +5,7 @@ This PowerShell script changes the working directory to the user's Dropbox folder. .EXAMPLE PS> ./cd-dropbox - πŸ“‚C:\Users\Markus\Dropbox + πŸ“‚C:\Users\Markus\Dropbox (has 2 files and 4 subfolders) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -13,12 +13,14 @@ #> try { - $path = Resolve-Path "~/Dropbox" - if (-not(Test-Path "$path" -pathType container)) { - throw "No Dropbox folder at πŸ“‚$path - is Dropbox installed?" + if (-not(Test-Path "~/Dropbox" -pathType container)) { + throw "No πŸ“‚Dropbox folder in your home directory - is Dropbox installed?" } + $path = Resolve-Path "~/Dropbox" Set-Location "$path" - "πŸ“‚$path" + $files = Get-ChildItem $path -attributes !Directory + $folders = Get-ChildItem $path -attributes Directory + "πŸ“‚$path entered (has $($files.Count) files and $($folders.Count) subfolders)" exit 0 # success } catch { "⚠️ Error: $($Error[0])" diff --git a/scripts/cd-etc.ps1 b/scripts/cd-etc.ps1 index b2886dbb..49fd48bf 100755 --- a/scripts/cd-etc.ps1 +++ b/scripts/cd-etc.ps1 @@ -5,7 +5,7 @@ This PowerShell script changes the working directory to the /etc directory. .EXAMPLE PS> ./cd-etc - πŸ“‚C:\Windows\System32\drivers\etc + πŸ“‚C:\Windows\System32\drivers\etc (has 2 files and 3 subfolders) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -13,7 +13,7 @@ #> try { - if ($IsLinx) { + if ($IsLinux -or $IsMacOS) { $path = "/etc" } else { $path = Resolve-Path "$env:WINDIR\System32\drivers\etc" @@ -22,7 +22,9 @@ try { throw "No /etc directory at πŸ“‚$path" } Set-Location "$path" - "πŸ“‚$path" + $files = Get-ChildItem $path -attributes !Directory + $folders = Get-ChildItem $path -attributes Directory + "πŸ“‚$path entered (has $($files.Count) files and $($folders.Count) subfolders)" exit 0 # success } catch { "⚠️ Error: $($Error[0])" diff --git a/scripts/cd-fonts.ps1 b/scripts/cd-fonts.ps1 index e6ef247f..4a07c88b 100755 --- a/scripts/cd-fonts.ps1 +++ b/scripts/cd-fonts.ps1 @@ -5,7 +5,7 @@ This PowerShell script changes the working directory to the fonts folder. .EXAMPLE PS> ./cd-fonts - πŸ“‚C:\Windows\Fonts + πŸ“‚C:\Windows\Fonts (has 2 file and 3 subfolders) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -18,7 +18,9 @@ try { throw "No fonts folder at πŸ“‚$path" } Set-Location "$path" - "πŸ“‚$path" + $files = Get-ChildItem $path -attributes !Directory + $folders = Get-ChildItem $path -attributes Directory + "πŸ“‚$path entered (has $($files.Count) files and $($folders.Count) subfolders)" exit 0 # success } catch { "⚠️ Error: $($Error[0])" diff --git a/scripts/cd-home.ps1 b/scripts/cd-home.ps1 index 6f56b4cd..4bc04e13 100755 --- a/scripts/cd-home.ps1 +++ b/scripts/cd-home.ps1 @@ -5,7 +5,7 @@ This PowerShell script changes the working directory to the user's home directory. .EXAMPLE PS> ./cd-home.ps1 - πŸ“‚C:\Users\Markus entered (has 4 files and 7 folders) + πŸ“‚C:\Users\Markus entered (has 4 files and 7 subfolders) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -13,12 +13,12 @@ #> try { + if (-not(Test-Path "~" -pathType container)) { throw "No home directory at $path" } $path = Resolve-Path "~" - if (-not(Test-Path "$path" -pathType container)) { throw "No home directory 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) folders)" + "πŸ“‚$path entered (has $($files.Count) files and $($folders.Count) subfolders)" exit 0 # success } catch { "⚠️ Error: $($Error[0])" diff --git a/scripts/cd-logs.ps1 b/scripts/cd-logs.ps1 index 1f4cc98d..31a5e702 100755 --- a/scripts/cd-logs.ps1 +++ b/scripts/cd-logs.ps1 @@ -5,7 +5,7 @@ This PowerShell script changes the current working directory to the logs directory. .EXAMPLE PS> ./cd-logs - πŸ“‚/var/logs + πŸ“‚/var/logs entered (has 3 files and 2 subfolders) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -13,7 +13,7 @@ #> function GetLogsDir { - if ($IsLinux) { return "/var/logs" } + if ($IsLinux -or $IsMacOS) { return "/var/logs" } $WinDir = [System.Environment]::GetFolderPath('Windows') return "$WinDir\Logs" } @@ -21,7 +21,9 @@ function GetLogsDir { try { $path = GetLogsDir Set-Location "$path" - "πŸ“‚$path" + $files = Get-ChildItem $path -attributes !Directory + $folders = Get-ChildItem $path -attributes Directory + "πŸ“‚$path entered (has $($files.Count) files and $($folders.Count) subfolders)" exit 0 # success } catch { "⚠️ Error: $($Error[0])"