【问题标题】:How to show file and folder names along with terminal icons without showing current directory?如何在不显示当前目录的情况下显示文件和文件夹名称以及终端图标?
【发布时间】:2020-08-11 21:58:59
【问题描述】:

我想移除空间/区域显示

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

当我运行命令时:

Get-ChildItem | Format-Wide

其他细节:

  • 使用 Windows 终端和 Powershell
  • 屏幕截图中使用的字体:TerminessTTF NF
  • 使用Terminal-Icons

注意:命令

Get-ChildItem -Name

未能在此处显示我的主要目标类型的终端图标。

【问题讨论】:

  • 你的问题是什么?
  • 已更正,谢谢。

标签: windows powershell powershell-2.0 powershell-3.0 windows-terminal


【解决方案1】:

当您使用Format-* 命令时,您使用的是文件和目录对象的默认格式输出,它按目录对文件进行分组 - 因此目录名称位于顶部。

如果您想绕过这个,您必须编写自己的 format.ps1xml 文件,然后将格式添加到您的输出中。

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

指定 Typename 的 XML 小样本,根据需要自定义。

<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>

【讨论】:

  • 尝试从at.ps1xml 创建,收到以下错误:'c:\Windows\System32\WindowsPowerShell\v1.0\format.ps1xml' (NoPermissions (FileSystemError): Error: EPERM: operation not允许,打开 'c:\Windows\System32\WindowsPowerShell\v1.0\format.ps1xml')
  • 我会在您的脚本所在的用户目录中创建它。请按照我提供的链接中有关如何使用格式化数据的信息进行操作。
  • 我已按照链接中的说明创建了 /Mygciview.Format.ps1xml 并将其放入我的项目文件夹中。
  • 然后我做了一个自定义的power shell函数如下: function Format-TC { $files = Get-ChildItem foreach ($file in $files) { $file.PSObject.TypeNames.Insert(0, 'Mygciview.Format.ps1xml') # $file }}
  • 在插入语句中不要使用 XML 的名称,而是使用 TypeName。请遵循链接的文档。它确实有效。
猜你喜欢
  • 1970-01-01
  • 2013-06-24
  • 1970-01-01
  • 2014-09-17
  • 2019-02-10
  • 1970-01-01
  • 2011-05-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多