Improve list-formatted.ps1 and my-profile.ps1

This commit is contained in:
Markus Fleschutz 2021-04-10 09:11:56 +02:00
parent b351e570d9
commit 27aeeb9806
2 changed files with 22 additions and 20 deletions

View File

@ -6,24 +6,22 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Dir = "")
param($Directory = "$PWD")
function ListDirectory { param([string]$Path)
function ListDir { param([string]$Path)
$Items = get-childItem -path $Path
foreach ($Item in $Items) {
if ($Item.Name[0] -eq '.') { continue } # hidden file/dir
if ($Item.Mode -like "d*") {
New-Object PSObject -Property @{ Filename = "$($Item.Name)/" }
New-Object PSObject -Property @{ Name = "$($Item.Name)/" }
} else {
New-Object PSObject -Property @{ Filename = "$($Item.Name)" }
New-Object PSObject -Property @{ Name = "$($Item.Name)" }
}
}
}
try {
if ($Dir -eq "") {
$Dir = "$PWD"
}
ListDirectory $Dir | format-wide -autoSize
ListDir $Directory | format-wide -autoSize
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,9 +1,15 @@
# My PowerShell Profile
# =====================
# Welcome to 'my-profile.ps1' - this file defines the look&feel of PowerShell for the user.
# Simply comment/uncomment/adapt the following lines.
#
#
# Welcome to 'my-profile.ps1' - this file defines the look & feel of PowerShell.
# Comment, uncomment or adapt the following lines to your needs, please.
# My Welcome Message
# ------------------
write-host "+++ Welcome to PowerShell $($PSVersionTable.PSVersion) at $(hostname), it's $(Get-date) +++"
write-host ""
# My Command Prompt
# -----------------
@ -12,19 +18,17 @@
# function prompt { "$ " } # result is: $
function prompt {
if ($IsLinux) { $Username = $(whoami) } else { $Username = $env:USERNAME }
$host.ui.RawUI.WindowTitle = "$Username @ $(hostname)"
if ($IsLinux) { $User = $(whoami) } else { $User = $env:USERNAME }
$host.ui.RawUI.WindowTitle = "$User @ $(hostname)"
write-host -foregroundColor blue -noNewLine "$(Get-Location)"
return "> "
} # result is: C:\>
# My Alias Names
# My Alias Names (sorted alphabetically)
# --------------
set-alias -name lsf -value get-childitem # lsf means list directory formatted
set-alias -name ll -value get-childitem # ll = list long
set-alias -name lsf -value list-formatted.ps1 # lsf = list directory formatted in columns
# My Welcome Message
# ------------------
write-host "+++ Welcome to PowerShell $($PSVersionTable.PSVersion) at $(hostname), it's $(Get-date) +++"
write-host ""