From 27aeeb98062cc8f1e41e1725c624bb6306f0419e Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sat, 10 Apr 2021 09:11:56 +0200 Subject: [PATCH] Improve list-formatted.ps1 and my-profile.ps1 --- Scripts/list-formatted.ps1 | 14 ++++++-------- Scripts/my-profile.ps1 | 28 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Scripts/list-formatted.ps1 b/Scripts/list-formatted.ps1 index 035b3bf4..abac7143 100755 --- a/Scripts/list-formatted.ps1 +++ b/Scripts/list-formatted.ps1 @@ -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])" diff --git a/Scripts/my-profile.ps1 b/Scripts/my-profile.ps1 index 76e566c2..bf3730db 100755 --- a/Scripts/my-profile.ps1 +++ b/Scripts/my-profile.ps1 @@ -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 ""