Improve the cd-* scripts

This commit is contained in:
Markus Fleschutz 2021-10-19 08:24:17 +02:00
parent 32d2b76abb
commit e9bfd8cf10
19 changed files with 194 additions and 118 deletions

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's autostart folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Autostart folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Desktop"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the desktop folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Desktop"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Desktop folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Documents"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's documents folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Documents"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Documents folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Downloads"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's downloads folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Downloads"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Downloads folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Dropbox"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's Dropbox folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Dropbox"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Dropbox folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's home directory at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Home directory at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Music"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's music folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Music"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Music folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/OneDrive"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's OneDrive folder 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/OneDrive"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "OneDrive folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Pictures"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's pictures folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Pictures"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Pictures folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -18,11 +18,15 @@ function Get-CurrentUserSID { [CmdletBinding()] param()
}
$TargetDir = 'C:\$Recycle.Bin\' + "$(Get-CurrentUserSID)"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's recycle bin folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = 'C:\$Recycle.Bin\' + "$(Get-CurrentUserSID)"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Recycle bin folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Repos"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's Git repositories folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Repos"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Git repositories folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,15 +12,19 @@
Author: Markus Fleschutz · License: CC0
#>
if ($IsLinux) {
$TargetDir = resolve-path "/"
} else {
$TargetDir = resolve-path "C:\"
}
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the root directory at 📂$TargetDir does not exist (yet)"
try {
if ($IsLinux) {
$TargetDir = resolve-path "/"
} else {
$TargetDir = resolve-path "C:\"
}
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Root directory at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$PSScriptRoot"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the PowerShell scripts folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$PSScriptRoot"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "PowerShell scripts folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/.ssh"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's SSH folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/.ssh"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "SSH folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path ".."
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the folder 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path ".."
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "../.."
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the folder 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "../.."
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "../../.."
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the folder 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "../../.."
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "../../../.."
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the folder 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "../../../.."
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success

View File

@ -12,11 +12,15 @@
Author: Markus Fleschutz · License: CC0
#>
$TargetDir = resolve-path "$HOME/Videos"
if (-not(test-path "$TargetDir" -pathType container)) {
write-warning "Sorry, the user's videos folder at 📂$TargetDir does not exist (yet)"
try {
$TargetDir = resolve-path "$HOME/Videos"
if (-not(test-path "$TargetDir" -pathType container)) {
throw "Videos folder at 📂$TargetDir doesn't exist (yet)"
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
set-location "$TargetDir"
"📂$TargetDir"
exit 0 # success