Improve the cd-*.ps1 scripts

This commit is contained in:
Markus Fleschutz 2021-04-21 19:15:41 +02:00
parent 5706a11bdd
commit 7ab2795778
18 changed files with 127 additions and 152 deletions

View File

@ -13,7 +13,10 @@ cd-pics.ps1, go to the user's pictures folder
cd-repos.ps1, go to the user's Git repositories folder cd-repos.ps1, go to the user's Git repositories folder
cd-root.ps1, go to the root directory (C: on Windows) cd-root.ps1, go to the root directory (C: on Windows)
cd-scripts.ps1, go to the PowerShell Scripts folder cd-scripts.ps1, go to the PowerShell Scripts folder
cd-up.ps1, go one or multiple directories up cd-up.ps1, go one directory level up
cd-up2.ps1, go two directory levels up
cd-up3.ps1, go three directory levels up
cd-up4.ps1, go four directory levels up
cd-videos.ps1, go to the user's videos folder cd-videos.ps1, go to the user's videos folder
check-cpu-temp.ps1, checks the CPU temperature check-cpu-temp.ps1, checks the CPU temperature
check-dns-resolution.ps1, checks the DNS resolution with frequently used domain names check-dns-resolution.ps1, checks the DNS resolution with frequently used domain names

1 Script Description
13 cd-repos.ps1 go to the user's Git repositories folder
14 cd-root.ps1 go to the root directory (C: on Windows)
15 cd-scripts.ps1 go to the PowerShell Scripts folder
16 cd-up.ps1 go one or multiple directories up go one directory level up
17 cd-up2.ps1 go two directory levels up
18 cd-up3.ps1 go three directory levels up
19 cd-up4.ps1 go four directory levels up
20 cd-videos.ps1 go to the user's videos folder
21 check-cpu-temp.ps1 checks the CPU temperature
22 check-dns-resolution.ps1 checks the DNS resolution with frequently used domain names

View File

@ -99,7 +99,10 @@ Mega Collection of PowerShell Scripts
* [cd-repos.ps1](Scripts/cd-repos.ps1) - go to the user's Git repositories folder * [cd-repos.ps1](Scripts/cd-repos.ps1) - go to the user's Git repositories folder
* [cd-root.ps1](Scripts/cd-root.ps1) - go to the root directory (C:\ on Windows) * [cd-root.ps1](Scripts/cd-root.ps1) - go to the root directory (C:\ on Windows)
* [cd-scripts.ps1](Scripts/cd-scripts.ps1) - go to the PowerShell Scripts folder * [cd-scripts.ps1](Scripts/cd-scripts.ps1) - go to the PowerShell Scripts folder
* [cd-up.ps1](Scripts/cd-up.ps1) - go one or multiple directories up * [cd-up.ps1](Scripts/cd-up.ps1) - go one directory level up
* [cd-up2.ps1](Scripts/cd-up2.ps1) - go two directory levels up
* [cd-up3.ps1](Scripts/cd-up3.ps1) - go three directory levels up
* [cd-up4.ps1](Scripts/cd-up4.ps1) - go four directory levels up
* [cd-videos.ps1](Scripts/cd-videos.ps1) - go to the user's videos folder * [cd-videos.ps1](Scripts/cd-videos.ps1) - go to the user's videos folder
* [check-symlinks.ps1](Scripts/check-symlinks.ps1) - checks every symlink in the given directory tree * [check-symlinks.ps1](Scripts/check-symlinks.ps1) - checks every symlink in the given directory tree
* [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity * [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-desktop.ps1 .SYNTAX cd-desktop.ps1
.DESCRIPTION go to the user's desktop folder .DESCRIPTION go to the user's desktop folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Desktop"
$TargetDir = resolve-path "$HOME/Desktop" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -6,12 +6,11 @@
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Documents"
$TargetDir = resolve-path "$HOME/Documents" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-downloads.ps1 .SYNTAX cd-downloads.ps1
.DESCRIPTION go to the user's downloads folder .DESCRIPTION go to the user's downloads folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Downloads"
$TargetDir = resolve-path "$HOME/Downloads" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-dropbox.ps1 .SYNTAX cd-dropbox.ps1
.DESCRIPTION go to the user's Dropbox folder .DESCRIPTION go to the user's Dropbox folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Dropbox"
$TargetDir = resolve-path "$HOME/Dropbox" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-home.ps1 .SYNTAX cd-home.ps1
.DESCRIPTION go to the user's home folder .DESCRIPTION go to the user's home folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME"
$TargetDir = resolve-path "$HOME" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-music.ps1 .SYNTAX cd-music.ps1
.DESCRIPTION go to the user's music folder .DESCRIPTION go to the user's music folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Music"
$TargetDir = resolve-path "$HOME/Music" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-onedrive.ps1 .SYNTAX cd-onedrive.ps1
.DESCRIPTION go to the user's OneDrive folder .DESCRIPTION go to the user's OneDrive folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/OneDrive"
$TargetDir = resolve-path "$HOME/OneDrive" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-pics.ps1 .SYNTAX cd-pics.ps1
.DESCRIPTION go to the user's pictures folder .DESCRIPTION go to the user's pictures folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Pictures"
$TargetDir = resolve-path "$HOME/Pictures" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-repos.ps1 .SYNTAX cd-repos.ps1
.DESCRIPTION go to the user's Git repositories folder .DESCRIPTION go to the user's Git repositories folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Repos"
$TargetDir = resolve-path "$HOME/Repos" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,21 +1,19 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-root.ps1 .SYNTAX cd-root.ps1
.DESCRIPTION go to the root directory (C: on Windows) .DESCRIPTION go to the root directory (C: on Windows)
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { if ($IsLinux) {
if ($IsLinux) { $TargetDir = resolve-path "/"
$TargetDir = resolve-path "/" } else {
} else { $TargetDir = resolve-path "C:/"
$TargetDir = resolve-path "C:/" }
} if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-scripts.ps1 .SYNTAX cd-scripts.ps1
.DESCRIPTION go to the PowerShell Scripts folder .DESCRIPTION go to the PowerShell Scripts folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$PSScriptRoot"
$TargetDir = resolve-path "$PSScriptRoot" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-up.ps1 .SYNTAX cd-up.ps1
.DESCRIPTION go one directory up .DESCRIPTION go one directory level up
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path ".."
$TargetDir = resolve-path ".." if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-up2.ps1 .SYNTAX cd-up2.ps1
.DESCRIPTION go two directories up .DESCRIPTION go two directory levels up
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "../.."
$TargetDir = resolve-path "../.." if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-up3.ps1 .SYNTAX cd-up3.ps1
.DESCRIPTION go three directories up .DESCRIPTION go three directory levels up
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "../../.."
$TargetDir = resolve-path "../../.." if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-up4.ps1 .SYNTAX cd-up4.ps1
.DESCRIPTION go four directories up .DESCRIPTION go four directory levels up
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "../../../.."
$TargetDir = resolve-path "../../../.." if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0

View File

@ -1,17 +1,15 @@
#!/usr/bin/pwsh <#
<#
.SYNTAX cd-videos.ps1 .SYNTAX cd-videos.ps1
.DESCRIPTION go to the user's videos folder .DESCRIPTION go to the user's videos folder
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
try { $TargetDir = resolve-path "$HOME/Videos"
$TargetDir = resolve-path "$HOME/Videos" if (-not(test-path "$TargetDir" -container leaf)) {
set-location "$TargetDir" write-warning "Sorry, directory 📂$TargetDir is missing"
"📂$TargetDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }
set-location "$TargetDir"
"📂$TargetDir"
exit 0