이 모듈은 버전 3 이상용 PowerShell의 명령줄 편집 환경을 대체합니다. 다음을 제공합니다:
"기본 제공" 환경은 PowerShell 사용자에게 매우 친숙하도록 만들어졌습니다. 즉, 새로운 키 입력을 배울 필요가 없습니다.
PSReadLine
에 대한 유용한 리소스:
PSReadLine
에 대한 훌륭한 소개서(2013)를 작성했습니다.PSReadLine
에 시리즈(2014~2015)를 썼습니다.PSReadLine
원하는 대로 설치, 구성 및 조정하는 방법을 다루는 비디오(2021)를 보유하고 있습니다. PSReadLine
설치하는 방법에는 여러 가지가 있습니다.
PSReadLine
의 최신 시험판 버전을 설치하려면 1.6.0
이상의 PowerShellGet
버전이 필요합니다.
Windows PowerShell 5.1은 시험판 모듈 설치를 지원하지 않는 이전 버전의 PowerShellGet
제공하므로 Windows PowerShell 사용자는 관리자 권한 Windows PowerShell 세션에서 다음 명령을 실행하여 최신 PowerShellGet
(아직 설치되지 않은 경우)을 설치해야 합니다.
Install-Module - Name PowerShellGet - Force
Exit
PowerShellGet
설치한 후 다음을 실행하여 PSReadLine
의 최신 시험판 버전을 얻을 수 있습니다.
Install-Module PSReadLine - AllowPrerelease - Force
최신 안정 버전만 얻으려면 다음을 실행하세요.
Install-Module PSReadLine
시험판 버전에는 새로운 기능과 버그 수정이 포함되지만 새로운 문제가 발생할 수도 있습니다.
Windows 10에서 Windows PowerShell을 사용하거나 PowerShell 6+를 사용하는 경우 PSReadLine
이 이미 설치되어 있습니다. 최신 Windows 10의 Windows PowerShell에는 PSReadLine
버전 2.0.0-beta2
가 있습니다. PowerShell 6+ 버전에는 PSReadLine
의 최신 시험판 버전이 있습니다.
PowerShell V3/V4용 PowerShellGet의 미리 보기 릴리스에서는 GitHub에서의 다운로드가 더 이상 사용되지 않습니다. 우리는 GitHub에서 릴리스를 업데이트할 계획이 없으며 어느 시점에서는 GitHub에서 릴리스를 완전히 제거할 수도 있습니다.
Windows PowerShell V5 또는 V5.1 버전을 사용하거나 PowerShell 6+ 버전을 사용하는 경우 이 섹션을 건너뛰어도 됩니다.
그렇지 않은 경우 모듈을 가져오려면 프로필을 편집해야 합니다. 일반적으로 사용되는 두 가지 프로필 파일이 있으며 각각에 대한 지침이 약간 다릅니다. C:Users[User]DocumentsWindowsPowerShellprofile.ps1
파일은 모든 호스트(예: ISE
및 powershell.exe
)에 사용됩니다. 이 파일이 이미 있는 경우 다음을 추가해야 합니다.
if ( $host .Name -eq ' ConsoleHost ' )
{
Import-Module PSReadLine
}
또는 C:Users[User]DocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1
파일은 powershell.exe
전용입니다. 이 파일을 사용하면 다음을 간단히 추가할 수 있습니다.
Import-Module PSReadLine
두 경우 모두 아직 적절한 파일이 없다면 적절한 파일을 생성할 수 있습니다.
아래 제안된 명령 중 하나를 실행할 때 VSCode
터미널에서 열린 인스턴스를 포함하여 powershell.exe
, pwsh.exe
또는 pwsh
의 모든 인스턴스를 종료해야 합니다.
그런 다음 PSReadLine
이 로드되지 않았는지 확인하려면 다음을 수행하세요.
cmd.exe
, powershell_ise.exe
또는 Win+R
단축키를 통해 아래 제안된 명령을 실행하세요.bash
또는 zsh
)에서 아래 제안된 명령을 실행하세요. Windows PowerShell과 함께 제공되는 PSReadLine
버전을 사용하는 경우 powershell -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease"
실행해야 합니다. 참고: 이 명령을 실행하기 전에 PowershellGet이 업데이트되었는지 확인해야 합니다.
PowerShell 6 이상 버전과 함께 제공되는 PSReadLine
버전을 사용하는 경우 <path-to-pwsh-executable> -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease"
실행해야 합니다.
PowerShell 갤러리에서 직접 PSReadLine
설치한 경우 다음을 간단히 실행할 수 있습니다. powershell -noprofile -command "Update-Module PSReadLine -AllowPrerelease"
또는 <path-to-pwsh-executable> -noprofile -command "Update-Module PSReadLine -AllowPrerelease"
사용 중인 PowerShell 버전에 따라 다름)
다음과 같은 오류가 발생하는 경우:
Remove-Item : Cannot remove item
C:Users{yourName}DocumentsWindowsPowerShellModulesPSReadLineMicrosoft.PowerShell.PSReadLine.dll: Access to the path
'C:Users{yourName}DocumentsWindowsPowerShellModulesPSReadLineMicrosoft.PowerShell.PSReadLine.dll' is denied.
또는 다음과 같은 경고가 표시됩니다.
WARNING: The version '2.0.0' of module 'PSReadLine' is currently in use. Retry the operation after closing the applications.
그런 다음 PSReadLine
로드한 모든 프로세스를 종료하지 않았습니다.
사용을 시작하려면 모듈을 가져오세요.
Import-Module PSReadLine
Emacs 키 바인딩을 사용하려면 다음을 사용할 수 있습니다.
Set-PSReadLineOption - EditMode Emacs
현재 키 바인딩을 보려면:
Get-PSReadLineKeyHandler
많은 구성 옵션이 있습니다. Set-PSReadLineOption
옵션을 참조하세요. PSReadLine
해당 cmdlet에 대한 도움말과 about_PSReadLine
항목이 있습니다. 자세한 도움말은 해당 항목을 참조하세요.
사용자 지정 키 바인딩을 설정하려면 cmdlet Set-PSReadLineKeyHandler
사용하세요. 예를 들어 더 나은 기록 경험을 위해 다음을 시도해 보세요.
Set-PSReadLineKeyHandler - Key UpArrow - Function HistorySearchBackward
Set-PSReadLineKeyHandler - Key DownArrow - Function HistorySearchForward
이러한 바인딩을 사용하면 현재 명령줄이 비어 있는 경우 위쪽 화살표/아래쪽 화살표가 PowerShell/cmd처럼 작동합니다. 하지만 일부 텍스트를 입력한 경우 현재 입력한 텍스트로 시작하는 명령의 기록을 검색합니다.
Emacs 모드를 사용하지 않고 bash 스타일 완성을 활성화하려면 다음을 사용할 수 있습니다.
Set-PSReadLineKeyHandler - Key Tab - Function Complete
가능한 것의 더 흥미로운 예는 다음과 같습니다.
Set-PSReadLineKeyHandler - Chord ' " ' , " ' " `
- BriefDescription SmartInsertQuote `
- LongDescription " Insert paired quotes if not already on a quote " `
- ScriptBlock {
param ( $key , $arg )
$line = $null
$cursor = $null
[ Microsoft.PowerShell.PSConsoleReadLine ]::GetBufferState([ ref ] $line , [ ref ] $cursor )
if ( $line .Length -gt $cursor -and $line [ $cursor ] -eq $key .KeyChar ) {
# Just move the cursor
[ Microsoft.PowerShell.PSConsoleReadLine ]::SetCursorPosition( $cursor + 1 )
}
else {
# Insert matching quotes, move cursor to be in between the quotes
[ Microsoft.PowerShell.PSConsoleReadLine ]::Insert( " $ ( $key .KeyChar ) " * 2 )
[ Microsoft.PowerShell.PSConsoleReadLine ]::GetBufferState([ ref ] $line , [ ref ] $cursor )
[ Microsoft.PowerShell.PSConsoleReadLine ]::SetCursorPosition( $cursor - 1 )
}
}
이 예에서 작은따옴표나 큰따옴표를 입력하면 두 가지 일이 발생할 수 있습니다. 커서 뒤의 문자가 입력된 따옴표가 아닌 경우 일치하는 따옴표 쌍이 삽입되고 커서는 일치하는 따옴표 안에 배치됩니다. 커서 뒤의 문자가 입력된 따옴표인 경우 커서는 아무것도 삽입하지 않고 단순히 따옴표 너머로 이동됩니다. Resharper나 다른 스마트 편집기를 사용한다면 이 경험이 익숙할 것입니다.
이런 방식으로 작성된 핸들러를 사용하면 실행 취소를 올바르게 처리합니다. 두 따옴표는 한 번 실행 취소하면 실행 취소됩니다.
샘플 프로필 파일에는 확인할 수 있는 훌륭한 예제가 많이 있습니다. 이 파일은 PSReadLine
이 설치될 때 포함됩니다.
수정할 수 있는 다른 기본 제공 기능을 보려면 [Microsoft.PowerShell.PSConsoleReadLine]
의 공개 메서드를 참조하세요.
사용자 정의 키 바인딩에서 구현되지 않은 방식으로 명령줄을 변경하려면 다음 방법을 사용할 수 있습니다.
[ Microsoft.PowerShell.PSConsoleReadLine ]::GetBufferState
[ Microsoft.PowerShell.PSConsoleReadLine ]::Insert
[ Microsoft.PowerShell.PSConsoleReadLine ]::Replace
[ Microsoft.PowerShell.PSConsoleReadLine ]::SetCursorPosition
개발 및 기여 방법은 기여 가이드를 참조하세요.
Windows, Linux 또는 macOS에서 PSReadLine
빌드하려면 다음이 설치되어 있어야 합니다.
InvokeBuild
및 platyPS
빌드 스크립트 build.ps1
사용하여 프로젝트를 부트스트랩, 빌드 및 테스트할 수 있습니다.
./build.ps1 -Bootstrap
./build.ps1 -Configuration Debug -Framework net462
./build.ps1 -Configuration Debug -Framework netcoreapp2.1
./build.ps1 -Test -Configuration Debug -Framework net462
./build.ps1 -Test -Configuration Debug -Framework netcoreapp2.1
빌드 후 생성된 아티팩트는 <your-local-repo-root>/bin/Debug
에서 찾을 수 있습니다. 가져온 모듈을 로컬로 빌드된 모듈로 분리하려면 설치된 기본 PSReadLine 모듈을 자동으로 로드하지 않도록 pwsh -NonInteractive -NoProfile
실행해야 합니다. 그런 다음 Import-Module <your-local-repo-root>/bin/Debug/PSReadLine/PSReadLine.psd1
통해 로컬로 빌드된 PSReadLine 모듈을 로드합니다.
변경 로그는 여기에서 확인할 수 있습니다.
PSReadLine은 2-Clause BSD 라이선스에 따라 라이선스가 부여됩니다.
이 프로젝트에 참여하기 전에 행동 강령을 참조하십시오.
보안 문제가 있는 경우 보안 정책을 참조하세요.