Search code examples
windowspowershellpowershell-2.0powershell-3.0windows-terminal

How to show file and folder names along with terminal icons without showing current directory?


I want to remove the space/ area taken up in showing the

Directory: C:\Users\varun\Desktop\Projects\advanced-react-patterns-v2

when I run the command:

Get-ChildItem | Format-Wide

screenshot]

Additional details:

  • Using Windows Terminal & Powershell
  • Font used in the screenshot: TerminessTTF NF
  • Used Terminal-Icons

Note: The command

Get-ChildItem -Name

failed to show the terminal icons which kind of my main goal here.

enter image description here


Solution

  • When you are using a Format-* command you are using the default formatting output for the File and Directory objects, which groups files by directory - hence the directory name at the top.

    If you wanted to by pass this, you would have to write your own format.ps1xml file and then add the formatting to your output.

    $files = Get-ChildItem
    foreach ($file in $files) {
        $file.PSObject.TypeNames.Insert(0,'Custom.Output.Type')
        $file
    }
    

    Small sample of XML for the specified Typename, customise as you wish.

    <View>
        <Name>CustomFileFormatting</Name>
        <ViewSelectedBy>
            <TypeName>Custom.Output.Type</TypeName>
        </ViewSelectedBy>
        <TableControl>
            <AutoSize />
            <TableHeaders>
                <TableColumnHeader>
                    <Label>FullName</Label>
                    <Alignment>Left</Alignment>
                </TableColumnHeader>
            </TableHeaders>
            <TableRowEntries>
                <TableRowEntry>
                    <TableColumnItems>
                        <TableColumnItem>
                            <PropertyName>FSObject</PropertyName>
                        </TableColumnItem>
                    </TableColumnItems>
                </TableRowEntry>
            </TableRowEntries>
        </TableControl>
    </View>