使用 Powershell Core 6 作為預設 shell,快捷鍵為 Windows+X,我

使用 Powershell Core 6 作為預設 shell,快捷鍵為 Windows+X,我

我見過這個問題這不完全是一回事。我安裝了 Powershell Core 6。我通常使用快捷鍵Windows+開啟 Powershell X,然後使用I。現在我想要使用該快捷方式開啟 Powershell Core 6 而不是舊的 Powershell 5。

答案1

或者只需使用新的 Windows 終端並添加您選擇的任何內容。

Windows 終端機(預覽版)

Windows 終端是一種新型、現代化、快速、高效、強大且高效的終端應用程序,適用於命令列工具和 shell(例如命令提示字元、PowerShell 和 WSL)的使用者。其主要功能包括多個選項卡、Unicode 和 UTF-8 字元支援、GPU 加速文字渲染引擎以及自訂主題、樣式和配置。

這是一個開源項目,我們歡迎社區參與。如欲參與,請訪問https://github.com/microsoft/terminal

根據迄今為止的評論進行更新。

你無法自然地做你所追求的事情。您必須破解註冊表才能更改此設定。

然而,當您只需將pwsh 快捷方式固定到工作列上的第一個位置,然後只需按任務欄上的Win 鍵+ 1(或將其放置到位置9 的位置)時,為什麼還要費盡心思呢?

例如,在我的工作列上,我的 Windows Terminal、pwsh、powershell、powershell_ISE、VSCode、PowerShellStudio 位於位置 1、2、3、4、5、6。

在此輸入影像描述

因此,按 Win+# 啟動應用程式。不需要進行登錄機碼破解,並且需要 2 次擊鍵,而 3 次擊鍵。 在此輸入影像描述

答案2

使用此工具可以編輯 Win+X 選單: https://winaero.com/download-winx-menu-editor-allows-you-to-add-or-remove-winx-menu-items

螢幕截圖

在這裡,有一些團體。使用新增程式按鈕將其新增至您喜歡的任何群組。然後,按下「重新啟動資源管理器」(注意:這將關閉所有檔案總管視窗!)

答案3

@vssher 建議的另一個選擇是使用康埃穆或者微軟終端
設定為預設終端:


Pwsh.exe要配置在 ConEmu 中啟動的熱鍵:

  1. 設定啟動任務:預定義任務(命令組)
  2. +圖示或使用 ConEmu 的預設 [ Shells::PowerShell Core]
    1. 姓名 (顯示Group <#>: Powershell::Pwsh
    2. 熱鍵:選擇您想要的任何內容
    3. 新控制台的預設任務:開啟 ConEmu 時的預設 shell
    4. 工作列跳轉清單:將此任務新增至 ConEmu 工作列跳轉列表
    5. 預設外殼(Win+X):
      • Windows 10:使其成為Win+X選單中的預設值
      • Windows 11:不影響Win+X菜單
        • 雖然Win+X選單也可以在 Win <11 中手動修改,但它會在 11 中導致損壞(如果有人知道不會導致損壞的方法,請發表評論,我會對此進行修改)
    6. 任務參數:不需要,但可以定制
    7. 命令:
      pwsh.exe -NoExit -Command "Import-Module C:\Users\<username>\WindowsPowerShell\profile.ps1" -new_console:t:"Pwsh"
      
      • 若要作為管理終端啟動,請a:在先前新增t:-new_console:a:t:"Pwsh"
      • -Import-Module是可選的,但允許自訂提示profile.ps1
        #
        
        # ===========================================================
                ##::[[--- Powershell PS1 Profile ---]]::##
        # ===========================================================
        
          # Microsoft.PowerShell_profile.ps1 || Profile.ps1:
            # %UserProfile%\Documents\WindowsPowerShell
            # $env:UserProfile\Documents\WindowsPowerShell
        
        # ================================================================
        
            # Variables
        #----------------------------------------------------------------
        # ANSI:
          $ESC                              = [char]27
        
        # Host.PrivateData:
          $PD                               = $($Host.PrivateData)
        
        # Colors: 
          $Host.UI.RawUI.BackgroundColor    = ($bckgrnd = 'Black')
          $Host.UI.RawUI.ForegroundColor    = 'Gray'
        
          $PD.ErrorForegroundColor          = 'Red'
          $PD.ErrorBackgroundColor          = $bckgrnd
        
          $PD.WarningForegroundColor        = 'Magenta'
          $PD.WarningBackgroundColor        = $bckgrnd
        
          $PD.DebugForegroundColor          = 'Yellow'
          $PD.DebugBackgroundColor          = $bckgrnd
        
          $PD.VerboseForegroundColor        = 'Green'
          $PD.VerboseBackgroundColor        = $bckgrnd
        
          $PD.ProgressForegroundColor       = 'Yellow'
          $PD.ProgressBackgroundColor       = $bckgrnd
        
        #================================================================
        
            # Functions
        #----------------------------------------------------------------
        
        # Prompt:
          Function set-prompt {
            Param (
              [Parameter(Position=0)]
              [ValidateSet("Default","Test")]
              $Action
            )
        
            switch ($Action) {
              "Default" {
                Function global:prompt {
                  if (test-path variable:/PSDebugContext) { '[DBG]: ' }
                    write-host " "
                    write-host ("$ESC[48;2;40;40;40m$ESC[38;2;170;210;0m$(Get-Location) $ESC[0m $ESC[0m")
        
                  if ( $host.UI.RawUI.WindowTitle -match "Administrator" ) {
                    $Host.UI.RawUI.ForegroundColor = 'Red'
                    $(if ($nestedpromptlevel -ge 1) {
                      write-host ('PS $$ ') -ForegroundColor Red -NoNewLine
                    } else {
                      write-host ('PS $ ') -ForegroundColor Red -NoNewLine
                    })
                  } else {
                    $(if ($nestedpromptlevel -ge 1) {
                      write-host ('PS $$ ') -ForegroundColor Blue -NoNewLine
                    } else {
                      write-host ('PS $ ') -ForegroundColor Blue -NoNewLine
                    })
                  }
        
                  return " "
                }
              }
            }
          }
        
          set-prompt Default
        
        # Relaunch as Admin:
          function Relaunch-Admin { Start-Process -Verb RunAs wt }
          Set-Alias psa Relaunch-Admin
        
  3. Save settings


要導入ConEmu.xml我使用的配置:

  1. GitHub下載按鈕:下載原始文件→ 在文字編輯器中開啟
  2. 尋找/替換<username>%UserProfile% 資料夾名稱→ 儲存更改
  3. 透過 ConEmu 設定導入:WinKey+ Alt+ PImport...Save settings

答案4

這是我目前正在使用的解決方法。

如果您使用PowerShell $PROFILE,您可以插入一行pwsh.exe ,則可以在腳本的開頭。任何用於啟動 PowerShell 的 Windows 捷徑都會有效地掛接到電源外殼 6間接作為子進程電源外殼5

相關內容