這是這個問題的 PowerShell 版本。我希望 PowerShell在我沒有在提示中輸入任何文本的情況下ls按下。enter如何實作?
uj5u.com熱心網友回復:
以下代碼用于Set-PSReadLineKeyHandler定義要運行的腳本塊Enter。您可以將其放入您的$Profile檔案中以使其始終可用。
使用 Windows PowerShell 5.1 和 PowerShell Core 7.2.1 進行測驗。
Set-PSReadLineKeyHandler -Chord Enter -ScriptBlock {
# Copy current command-line input
$currentInput = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $currentInput, [ref] $null)
# If command line is empty...
if( $currentInput.Length -eq 0 ) {
# Enter new console command
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, 0, 'Get-ChildItem')
}
# Simulate pressing Enter
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444155.html
標籤:电源外壳
