mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Add PowerShell autocompletion feature
This commit is contained in:
parent
2ac251faa1
commit
99c693df39
3 changed files with 28 additions and 4 deletions
|
@ -615,7 +615,7 @@ opposed to this idea. Here's what `eval "$(pyenv init -)"` actually does:
|
||||||
|
|
||||||
2. **Installs autocompletion.** This is entirely optional but pretty
|
2. **Installs autocompletion.** This is entirely optional but pretty
|
||||||
useful. Sourcing `$(pyenv root)/completions/pyenv.bash` will set that
|
useful. Sourcing `$(pyenv root)/completions/pyenv.bash` will set that
|
||||||
up. There are also completions for Zsh and Fish.
|
up. There are also completions for Zsh, Fish and PowerShell.
|
||||||
|
|
||||||
3. **Rehashes shims.** From time to time you'll need to rebuild your
|
3. **Rehashes shims.** From time to time you'll need to rebuild your
|
||||||
shim files. Doing this on init makes sure everything is up to
|
shim files. Doing this on init makes sure everything is up to
|
||||||
|
|
17
completions/pyenv.pwsh
Normal file
17
completions/pyenv.pwsh
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
$scriptblock = {
|
||||||
|
param($wordToComplete, $commandAst, $cursorPosition)
|
||||||
|
$words = $commandAst.ToString()
|
||||||
|
if ( $wordToComplete ) {
|
||||||
|
$matches = (($words[0..$cursorPosition] -join '') | Select-String -Pattern "\s+" -AllMatches).Matches
|
||||||
|
if ( $matches ) {
|
||||||
|
$cursorPosition = $matches[-1].Index - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$words = $words[0..$cursorPosition] -join '' -split "\s+"
|
||||||
|
if ( $words.Count -ge 2 ) {
|
||||||
|
pyenv completions $words[1] | where { $_ -match $wordToComplete }
|
||||||
|
} else {
|
||||||
|
pyenv commands | where { $_ -match $wordToComplete }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Register-ArgumentCompleter -Native -CommandName pyenv -ScriptBlock $scriptblock
|
|
@ -281,7 +281,14 @@ function print_env() {
|
||||||
function print_completion() {
|
function print_completion() {
|
||||||
completion="${root}/completions/pyenv.${shell}"
|
completion="${root}/completions/pyenv.${shell}"
|
||||||
if [ -r "$completion" ]; then
|
if [ -r "$completion" ]; then
|
||||||
|
case "$shell" in
|
||||||
|
pwsh )
|
||||||
|
echo "iex (gc $completion -Raw)"
|
||||||
|
;;
|
||||||
|
* )
|
||||||
echo "source '$completion'"
|
echo "source '$completion'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue