你见过启动耗时25秒的shell吗?

Snemc 2026-09-26 12:01 1



微软什么时候优化下这坨大份

ai时代下搞个好用的shell很难吗

最新回复 (7)
  • John_Smith 09-26 12:04
    1楼

    是不是装太多插件了 ^-^

  • Snemc 楼主 09-26 12:05
    2楼
     echo $PROFILE
    D:\Users\xz\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
    ~
    PS> cat D:\Users\xz\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
    # 入口:加载拆分配置
    $configRoot = Join-Path (Split-Path -Parent $PROFILE) 'config'
    $baseConfig = Join-Path $configRoot '01_base.ps1'
    if (Test-Path -LiteralPath $baseConfig) {
    . $baseConfig
    }
    else {
    Write-Warning "PowerShell 基础配置不存在: $baseConfig"
    }
    ~
    PS> cat $configDir
    Get-Content: Unable to get content because it is a directory: 'D:\Users\xz\Documents\PowerShell\config'. Please use 'Get-ChildItem' instead.
    ~
    PS> cat D:\Users\xz\Documents\PowerShell\config\01_base.ps1
    # 基础配置(参考 jswysnemc/dotfiles powershell/01_base.ps1,按本机路径适配)
    # 加载入口:Microsoft.PowerShell_profile.ps1

    # ===== 编码 =====
    $OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8

    # ===== PATH(仅在缺失时追加,避免重复)=====
    function Add-PathIfMissing {
    param(
    [Parameter(Mandatory = $true)]
    [string]$Directory
    )
    if (-not (Test-Path -LiteralPath $Directory)) {
    return
    }
    $pathParts = $env:Path -split [IO.Path]::PathSeparator
    if ($pathParts -notcontains $Directory) {
    $env:Path = $Directory + [IO.Path]::PathSeparator + $env:Path
    }
    }

    Add-PathIfMissing -Directory 'D:\Apps\fzf'
    Add-PathIfMissing -Directory 'D:\Apps\zoxide'
    Add-PathIfMissing -Directory (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links')

    # ===== fzf / zoxide 环境(双栏:左列表 + 右预览)=====
    $configDir = Split-Path -Parent $MyInvocation.MyCommand.Path
    $fzfPreviewScript = Join-Path $configDir 'fzf-preview.ps1'
    # 1. 右侧 50% 预览;Ctrl+/ 开关预览
    # 2. 预览命令整体加双引号,避免 fzf 把 -NoProfile 拆成独立选项
    $env:FZF_DEFAULT_OPTS = @(
    '--height=70%'
    '--layout=reverse'
    '--border'
    '--info=inline'
    '--preview-window=right:50%:wrap'
    '--bind=ctrl-j:down,ctrl-k:up'
    '--bind=ctrl-/:toggle-preview'
    "--preview=""pwsh -NoProfile -NonInteractive -File '$fzfPreviewScript' {}"""
    ) -join ' '
    $env:_ZO_FZF_OPTS = $env:FZF_DEFAULT_OPTS
    $env:_ZO_ECHO = '0'
    $env:_ZO_EXCLUDE_DIRS = '*\.git\*;*\node_modules\*;C:\Windows\*'

    function ff {
    fzf @args
    }

    # ===== 双行提示符 =====
    # 第一行:路径(家目录缩写为 ~);第二行:输入光标
    function prompt {
    $location = $executionContext.SessionState.Path.CurrentLocation
    $path = $location.Path
    $homePath = [Environment]::GetFolderPath('UserProfile')
    if ($path.StartsWith($homePath, [System.StringComparison]::OrdinalIgnoreCase)) {
    $path = '~' + $path.Substring($homePath.Length)
    }

    $Host.UI.RawUI.WindowTitle = $location.Path

    # 管理员会话加前缀,便于区分
    $prefix = ''
    try {
    $identity = [Security.Principal.WindowsIdentity]::GetCurrent()
    $principal = [Security.Principal.WindowsPrincipal]$identity
    if ($principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    $prefix = '[Admin] '
    }
    }
    catch {
    }

    if ($PSVersionTable.PSVersion.Major -ge 7) {
    return "`e[36m$prefix$path`e[0m`nPS> "
    }

    return "$prefix$path`nPS> "
    }

    # ===== PSReadLine =====
    if (Get-Module -ListAvailable PSReadLine) {
    Import-Module PSReadLine

    Set-PSReadLineOption -EditMode Windows
    Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    Set-PSReadLineOption -BellStyle None
    Set-PSReadLineOption -ShowToolTips
    Set-PSReadLineOption -MaximumHistoryCount 10000

    # 1. 关闭历史预测,历史不参与补全
    # 2. Tab 使用菜单补全,候选来自 PowerShell / carapace
    try {
    Set-PSReadLineOption -PredictionSource None
    }
    catch {
    }

    Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
    Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
    Set-PSReadLineKeyHandler -Key RightArrow -Function ForwardChar

    if ($PSVersionTable.PSVersion.Major -ge 7) {
    Set-PSReadLineOption -Colors @{ 'Selection' = "`e[7m" }
    }
    }

    # ===== PSFzf:路径/历史模糊查找,不接管 Tab =====
    if ((Get-Command fzf -ErrorAction SilentlyContinue) -and (Get-Module -ListAvailable PSFzf)) {
    Import-Module PSFzf
    Set-PsFzfOption `
    -PSReadlineChordProvider 'Ctrl+t' `
    -PSReadlineChordReverseHistory 'Ctrl+r' `
    -PSReadlineChordSetLocation 'Alt+c'
    }

    # ===== carapace:第三方命令/参数补全 =====
    # 可选:$env:CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense'
    if (Get-Command carapace -ErrorAction SilentlyContinue) {
    carapace _carapace | Out-String | Invoke-Expression
    }

    # ===== zoxide(须在 _ZO_* 环境变量之后)=====
    if (Get-Command zoxide -ErrorAction SilentlyContinue) {
    Invoke-Expression (& { (zoxide init powershell --cmd z | Out-String) })
    }

    # 交互式目录跳转
    function c {
    if (-not (Get-Command zoxide -ErrorAction SilentlyContinue)) {
    Write-Error 'zoxide 未安装'
    return
    }
    $target = zoxide query -i
    if ($target) {
    Set-Location -LiteralPath $target
    }
    }

    # 命令速查:explain git commit
    function explain {
    if ($args.Count -eq 0) {
    Write-Error '用法: explain <command>'
    return
    }
    $cmd = $args -join '+'
    Invoke-RestMethod -Uri "https://cheat.sh/$cmd" -UseBasicParsing
    }
  • Snemc 楼主 09-26 12:06
    3楼

    看楼下的配置,就这么多

  • yyjeqhc 09-26 12:22
    4楼

    直接把配置文件问gpt看看吧,肯定是profile加载耗时的,不是启动powershell耗时

  • miku 09-26 12:30
    5楼

    要么是插件问题,要么电脑太垃圾了


    不然怎么会只有你反馈?

  • Enze 09-26 12:36
    6楼

    先怀疑自己的硬件、设置,排查过了再去质疑月活十四亿的流行操作系统(和它的 powershell)

  • 虹夏 09-26 12:39
    7楼

    我之前也遇到过,应该是插件问题



    不然怎么会只有你反馈?



    这个不至于这么说吧,还是有人有同样问题的,网络上反馈已经不少了

* 帖子来源Linux.do
返回