How to add Terminal-Icons to a powershell function

160 Views Asked by At

I have this function:

function Get-ChildItemUnix {
    Get-ChildItem $Args[0] |
        Format-Table Mode, @{N='Owner';E={(Get-Acl $_.FullName).Owner}}, Length, LastWriteTime, @{N='Name';E={if($_.Target) {$_.Name+' -> '+$_.Target} else {$_.Name}}}
}
New-Alias ll Get-ChildItemUnix

From this question

The thing is that I can see thar I want to show Icons in the result of the function like the ls command

enter image description here

The ll personalized command result is this

enter image description here

1

There are 1 best solutions below

0
C. Aknesil On

You can use Unicode characters like and as you use any other character like 'a' or 'b' as long as the underlying font includes them.

A small example that you can build from is the following. Printing names of the content of the current directory with with a different symbol depending whether it is a file or a folder.

PS> Get-ChildItem | 
      Format-Table @{N='Name'
                     E={if ($_ -is [System.IO.DirectoryInfo]) {
                          " $($_.Name)"
                        } else {
                          " $($_.Name)"
                        }}}

Name
----
 my-folder
 my-file