sourcecode

PowerShell 탭 완성을 Bash와 동일하게 하는 방법

codebag 2023. 4. 8. 08:27
반응형

PowerShell 탭 완성을 Bash와 동일하게 하는 방법

현재 디렉터리에 다음 파일이 있다고 가정합니다.

buildBar.bat
buildFoo.bat
buildHouse.bat

명령 프롬프트에서 다음을 입력합니다../bu를 클릭합니다.

  • Bash에서는 다음과 같이 확장됩니다../build

  • PowerShell에서는 다음과 같이 확장됩니다../buildBar.bat-- 목록의 첫 번째 항목입니다.

  • Cmd의 동작은 PowerShell과 동일합니다.

저는 Bash 동작을 선호합니다. PowerShell을 Bash처럼 동작시킬 수 있는 방법이 있습니까?

PowerShell의 새로운 버전에는 PSReadline이 포함되어 있으며, 이 기능을 사용할 수 있습니다.

Set-PSReadlineKeyHandler -Key Tab -Function Complete

또는 화살표 키를 사용하여 사용 가능한 옵션을 탐색할 수 있는 bash처럼 하려면 다음 절차를 수행합니다.

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

이 명령어를 영속적으로 설정하려면 다음 명령어를 powershell 프로파일에 추가합니다.$PROFILE(통상%UserProfile%\Documents\WindowsPowerShell\profile.ps1Windows PowerShell 5.x 및%UserProfile%\Documents\PowerShell\profile.ps1(PowerShell 6+)의 경우).

PSReadline을 사용하여 PowerShell에서 Bash 스타일의 완료를 실행할 수 있게 되었습니다.

PowerShell에서 블로그 투고 Bash와 같은완성을 확인하십시오.

tab는 명령어 이름만 완성하고 이전 인수 또는 파라미터는 완성하지 않습니다.

또한 다음 키바인딩을 설정한 이력 인수를 사용하여 명령어 전체를 자동 완성합니다.

Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

이제 명령 이름의 몇 글자를 입력하고 위쪽/아래쪽 화살표를 사용하여 기록에서 이 명령을 자동으로 완료합니다.

실시간 절약.


상세보기: PowerShell 전원 켜기

여기 보세요. 당신의 욕구가 아니라.

Power Tab

하지만 PowerShell 콘솔의 탭 확장 기능은 최적의 기능이라고 생각합니다.

# keep or reset to powershell default
Set-PSReadlineKeyHandler -Key Shift+Tab -Function TabCompletePrevious

# define Ctrl+Tab like default Tab behavior
Set-PSReadlineKeyHandler -Key Ctrl+Tab -Function TabCompleteNext

# define Tab like bash
Set-PSReadlineKeyHandler -Key Tab -Function Complete

TabExpansion 함수를 변경하여 원하는 기능을 수행합니다.처음 키를 누른 위치에서 새 제안 수정 탭을 다시 누르면 마지막까지 완료될 수 있습니다.저는 실제 행동을 매우 선호합니다. 가능한 한 빨리 라인을 작성해야 합니다.마지막으로 와일드카드 확장도 잊지 마십시오.예를 들어 bu*h[Tab]는 자동으로 빌드 완료House.bat

Powershell Core를 사용하면 예측 기능을 설정할 수 있습니다.PSReadLine을 히스토리로 자동 제안 받기 위한 소스 속성입니다.상세한 것에 대하여는, YouTube 비디오를 참조해 주세요.https://youtu.be/I0iIZe0dUNw

실제로 bash 동작은/etc/inputrc디스트로마다 크게 다릅니다.

PowerShell을 정상적인 디폴트로 동작시키는 방법(Gentoo, CentOS)은 다음과 같습니다.

# Press tab key to get a list of possible completions (also on Ctrl+Space)

Set-PSReadlineKeyHandler -Chord Tab -Function PossibleCompletions


# Search history based on input on PageUp/PageDown

Set-PSReadlineKeyHandler -Key PageUp -Function  HistorySearchBackward
Set-PSReadlineKeyHandler -Key PageDown -Function HistorySearchForward


# If you feel cursor should be at the end of the line after pressing PageUp/PageDown (saving you an End press), you may add:

Set-PSReadLineOption -HistorySearchCursorMovesToEnd

# Set-PSReadLineOption -HistorySearchCursorMovesToEnd:$False to remove

언급URL : https://stackoverflow.com/questions/8264655/how-to-make-powershell-tab-completion-work-like-bash

반응형