mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-25 11:28:17 +02:00
Improved some cd-*.ps1 scripts
This commit is contained in:
parent
257c2c3d82
commit
c35fcd8ea0
@ -13,13 +13,16 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
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"
|
$path = Resolve-Path "~/Desktop"
|
||||||
} else {
|
} else {
|
||||||
$path = [Environment]::GetFolderPath('DesktopDirectory')
|
$path = [Environment]::GetFolderPath('DesktopDirectory')
|
||||||
}
|
if (-not(Test-Path "$path" -pathType container)) {
|
||||||
if (-not(Test-Path "$path" -pathType container)) {
|
throw "No desktop folder at 📂$path yet"
|
||||||
throw "No desktop folder at 📂$path"
|
}
|
||||||
}
|
}
|
||||||
Set-Location "$path"
|
Set-Location "$path"
|
||||||
"📂$path"
|
"📂$path"
|
||||||
|
@ -13,13 +13,16 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
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"
|
$path = Resolve-Path "~/Documents"
|
||||||
} else {
|
} else {
|
||||||
$path = [Environment]::GetFolderPath('MyDocuments')
|
$path = [Environment]::GetFolderPath('MyDocuments')
|
||||||
}
|
if (-not(Test-Path "$path" -pathType container)) {
|
||||||
if (-not(Test-Path "$path" -pathType container)) {
|
throw "No documents folder at 📂$path yet"
|
||||||
throw "No documents folder at 📂$path"
|
}
|
||||||
}
|
}
|
||||||
Set-Location "$path"
|
Set-Location "$path"
|
||||||
$files = Get-ChildItem $path -attributes !Directory
|
$files = Get-ChildItem $path -attributes !Directory
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
try {
|
try {
|
||||||
if ($IsLinux -or $IsMacOS) {
|
if ($IsLinux -or $IsMacOS) {
|
||||||
if (-not(Test-Path "~/Downloads" -pathType container)) {
|
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"
|
$path = Resolve-Path "~/Downloads"
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
This PowerShell script changes the working directory to the user's Dropbox folder.
|
This PowerShell script changes the working directory to the user's Dropbox folder.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-dropbox
|
PS> ./cd-dropbox
|
||||||
📂C:\Users\Markus\Dropbox
|
📂C:\Users\Markus\Dropbox (has 2 files and 4 subfolders)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -13,12 +13,14 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$path = Resolve-Path "~/Dropbox"
|
if (-not(Test-Path "~/Dropbox" -pathType container)) {
|
||||||
if (-not(Test-Path "$path" -pathType container)) {
|
throw "No 📂Dropbox folder in your home directory - is Dropbox installed?"
|
||||||
throw "No Dropbox folder at 📂$path - is Dropbox installed?"
|
|
||||||
}
|
}
|
||||||
|
$path = Resolve-Path "~/Dropbox"
|
||||||
Set-Location "$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
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
This PowerShell script changes the working directory to the /etc directory.
|
This PowerShell script changes the working directory to the /etc directory.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-etc
|
PS> ./cd-etc
|
||||||
📂C:\Windows\System32\drivers\etc
|
📂C:\Windows\System32\drivers\etc (has 2 files and 3 subfolders)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($IsLinx) {
|
if ($IsLinux -or $IsMacOS) {
|
||||||
$path = "/etc"
|
$path = "/etc"
|
||||||
} else {
|
} else {
|
||||||
$path = Resolve-Path "$env:WINDIR\System32\drivers\etc"
|
$path = Resolve-Path "$env:WINDIR\System32\drivers\etc"
|
||||||
@ -22,7 +22,9 @@ try {
|
|||||||
throw "No /etc directory at 📂$path"
|
throw "No /etc directory at 📂$path"
|
||||||
}
|
}
|
||||||
Set-Location "$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
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
This PowerShell script changes the working directory to the fonts folder.
|
This PowerShell script changes the working directory to the fonts folder.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-fonts
|
PS> ./cd-fonts
|
||||||
📂C:\Windows\Fonts
|
📂C:\Windows\Fonts (has 2 file and 3 subfolders)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -18,7 +18,9 @@ try {
|
|||||||
throw "No fonts folder at 📂$path"
|
throw "No fonts folder at 📂$path"
|
||||||
}
|
}
|
||||||
Set-Location "$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
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
This PowerShell script changes the working directory to the user's home directory.
|
This PowerShell script changes the working directory to the user's home directory.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-home.ps1
|
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
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -13,12 +13,12 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (-not(Test-Path "~" -pathType container)) { throw "No home directory at $path" }
|
||||||
$path = Resolve-Path "~"
|
$path = Resolve-Path "~"
|
||||||
if (-not(Test-Path "$path" -pathType container)) { throw "No home directory at $path" }
|
|
||||||
Set-Location "$path"
|
Set-Location "$path"
|
||||||
$files = Get-ChildItem $path -attributes !Directory
|
$files = Get-ChildItem $path -attributes !Directory
|
||||||
$folders = 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
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
This PowerShell script changes the current working directory to the logs directory.
|
This PowerShell script changes the current working directory to the logs directory.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-logs
|
PS> ./cd-logs
|
||||||
📂/var/logs
|
📂/var/logs entered (has 3 files and 2 subfolders)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
function GetLogsDir {
|
function GetLogsDir {
|
||||||
if ($IsLinux) { return "/var/logs" }
|
if ($IsLinux -or $IsMacOS) { return "/var/logs" }
|
||||||
$WinDir = [System.Environment]::GetFolderPath('Windows')
|
$WinDir = [System.Environment]::GetFolderPath('Windows')
|
||||||
return "$WinDir\Logs"
|
return "$WinDir\Logs"
|
||||||
}
|
}
|
||||||
@ -21,7 +21,9 @@ function GetLogsDir {
|
|||||||
try {
|
try {
|
||||||
$path = GetLogsDir
|
$path = GetLogsDir
|
||||||
Set-Location "$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
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user