执行步骤

按照以下步骤操作可以轻松地完成配置:

  1. 以管理员的身份打开 PowerShell。

  2. 复制并粘贴下面提供的命令到 PowerShell 窗口中。

  3. 按 Enter 键运行命令。

  4. 将配置复制并保存

  5. 保存配置


具体步骤

以管理员的身份打开 PowerShell,并复制并粘贴执行下面提供的命令,运行后会跳出 VSCode 窗口

code $PROFILE

将以下配置复制到 VSCode 并保存

# 传统 Linux 风格的 ll
function ll {
    param([string]$Path = ".")
    
    # 定义颜色
    $colors = @{
        Directory = "Cyan"
        Hidden = "DarkGray"
        Executable = "Green"
        Compressed = "Magenta"
        Default = "White"
    }
    
    # 显示目录路径表头
    $fullPath = (Resolve-Path $Path).Path
    Write-Host "`n    Directory: $fullPath`n"
    
    # 显示列标题
    $headerFormat = "{0,-12} {1,-15} {2,10} {3,19} {4}"
    Write-Host ($headerFormat -f "Permissions", "Owner", "Size", "LastWriteTime", "Name") -ForegroundColor White
    Write-Host ($headerFormat -f "-----------", "-----", "----", "-------------", "----") -ForegroundColor White
    
    Get-ChildItem -Path $Path -Force | ForEach-Object {
        # 判断文件类型
        $isDir = $_.PSIsContainer
        $isHidden = $_.Attributes -match "Hidden"
        $isExe = $_.Extension -match "\.(exe|bat|cmd|ps1|msi|com)$"
        $isCompressed = $_.Extension -match "\.(zip|rar|7z|gz|tar|bz2)$"
        
        # 确定颜色
        if ($isDir) { $color = $colors.Directory }
        elseif ($isHidden) { $color = $colors.Hidden }
        elseif ($isExe) { $color = $colors.Executable }
        elseif ($isCompressed) { $color = $colors.Compressed }
        else { $color = $colors.Default }
        
        # 格式化大小
        $size = if ($isDir) { "<DIR>" } else {
            if ($_.Length -lt 1KB) { "$($_.Length)B" }
            elseif ($_.Length -lt 1MB) { "$([math]::Round($_.Length/1KB,2))KB" }
            elseif ($_.Length -lt 1GB) { "$([math]::Round($_.Length/1MB,2))MB" }
            else { "$([math]::Round($_.Length/1GB,2))GB" }
        }
        
        # 名称加斜杠(如果是目录)
        $name = if ($isDir) { "$($_.Name)/" } else { $_.Name }
        
        # 获取所有者(修复版)并截断为15字符
        $owner = try { 
            $acl = Get-Acl $_.FullName -ErrorAction SilentlyContinue
            if ($acl -and $acl.Owner) {
                ($acl.Owner -split "\\")[-1]
            } else {
                "N/A"
            }
        } catch { 
            "N/A" 
        }
        
        # 截断 Owner 为 15 个字符
        if ($owner.Length -gt 15) {
            $owner = $owner.Substring(0, 15)
        }
        
        # 逐行输出带颜色
        Write-Host ("{0,-12} {1,-15} {2,10} {3,19} " -f $_.Mode, $owner, $size, $_.LastWriteTime.ToString("yyyy-MM-dd HH:mm")) -NoNewline
        Write-Host $name -ForegroundColor $color
    }
    
    Write-Host ""  # 结尾空行
}

现在就能直接在 PowerShell 中直接使用 ll 命令了

使用 ll 命令,获取更详细的返回效果