mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-26 23:58:41 +01:00
Improve list-formatted.ps1 and my-profile.ps1
This commit is contained in:
parent
b351e570d9
commit
27aeeb9806
@ -6,24 +6,22 @@
|
|||||||
.NOTES Author: Markus Fleschutz / License: CC0
|
.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
|
$Items = get-childItem -path $Path
|
||||||
foreach ($Item in $Items) {
|
foreach ($Item in $Items) {
|
||||||
|
if ($Item.Name[0] -eq '.') { continue } # hidden file/dir
|
||||||
if ($Item.Mode -like "d*") {
|
if ($Item.Mode -like "d*") {
|
||||||
New-Object PSObject -Property @{ Filename = "$($Item.Name)/" }
|
New-Object PSObject -Property @{ Name = "$($Item.Name)/" }
|
||||||
} else {
|
} else {
|
||||||
New-Object PSObject -Property @{ Filename = "$($Item.Name)" }
|
New-Object PSObject -Property @{ Name = "$($Item.Name)" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($Dir -eq "") {
|
ListDir $Directory | format-wide -autoSize
|
||||||
$Dir = "$PWD"
|
|
||||||
}
|
|
||||||
ListDirectory $Dir | format-wide -autoSize
|
|
||||||
exit 0
|
exit 0
|
||||||
} catch {
|
} catch {
|
||||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
# My PowerShell Profile
|
# My PowerShell Profile
|
||||||
# =====================
|
# =====================
|
||||||
# Welcome to 'my-profile.ps1' - this file defines the look&feel of PowerShell for the user.
|
# Welcome to 'my-profile.ps1' - this file defines the look & feel of PowerShell.
|
||||||
# Simply comment/uncomment/adapt the following lines.
|
# 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
|
# My Command Prompt
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|
||||||
@ -12,19 +18,17 @@
|
|||||||
# function prompt { "$ " } # result is: $
|
# function prompt { "$ " } # result is: $
|
||||||
|
|
||||||
function prompt {
|
function prompt {
|
||||||
if ($IsLinux) { $Username = $(whoami) } else { $Username = $env:USERNAME }
|
if ($IsLinux) { $User = $(whoami) } else { $User = $env:USERNAME }
|
||||||
$host.ui.RawUI.WindowTitle = "$Username @ $(hostname)"
|
$host.ui.RawUI.WindowTitle = "$User @ $(hostname)"
|
||||||
write-host -foregroundColor blue -noNewLine "$(Get-Location)"
|
write-host -foregroundColor blue -noNewLine "$(Get-Location)"
|
||||||
return "> "
|
return "> "
|
||||||
} # result is: C:\>
|
} # 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 ""
|
|
||||||
|
Loading…
Reference in New Issue
Block a user