PowerShell New-CommandWrapper : Supply values for the following parameters

后端 未结 1 2013
情歌与酒
情歌与酒 2021-01-26 20:56

I mean to colorize the output of ls. I checked Powershell: Properly coloring Get-Childitem output once and for all.

The two options appear to be:

相关标签:
1条回答
  • 2021-01-26 21:45

    As mentioned in the comments, New-CommandWrapper is packaged as a script, rather than as a function, so you'll need to edit the script file slightly if you want to dot-source it:

    1. Insert function New-CommandWrapper { at the very top of New-CommandWrapper.ps1
    2. Add an } on the very last line

    Now you can dot-source it (from your profile if need be) and use the example given in the linked answer:

    PS C:\> . .\path\to\New-CommandWrapper.ps1
    PS C:\> New-CommandWrapper Out-Default `
    >>>    -Process {
    >>>        if(($_ -is [System.IO.DirectoryInfo]) -or ($_ -is [System.IO.FileInfo]))
    >>>        {if(-not ($notfirst)) {
    >>>           Write-Host "    Directory: $(pwd)`n"           
    >>>           Write-Host "Mode                LastWriteTime     Length Name"
    >>>           Write-Host "----                -------------     ------ ----"
    >>>           $notfirst=$true
    >>>           }
    >>>           if ($_ -is [System.IO.DirectoryInfo]) {
    >>>           Write-host ("{0,-7} {1,25} {2,10} {3}" -f $_.mode, ([String]::Format("{0,10}  {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t"))), $_.length, $_.name) -foregroundcolor "yellow" }
    >>>           else {
    >>>           Write-host ("{0,-7} {1,25} {2,10} {3}" -f $_.mode, ([String]::Format("{0,10}  {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t"))), $_.length, $_.name) -foregroundcolor "green" }
    >>>           $_ = $null
    >>>        }
    >>>} 
    
    0 讨论(0)
提交回复
热议问题