-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from jacquindev/main
Add ability to customize pyenv-win-venv installation location
- Loading branch information
Showing
7 changed files
with
199 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
@ECHO OFF | ||
@REM Alias for pyenv-win-venv.bat | ||
"%USERPROFILE%\.pyenv-win-venv\bin\pyenv-win-venv.bat" %* | ||
|
||
@REM "%USERPROFILE%\.pyenv-win-venv\bin\pyenv-win-venv.bat" %* | ||
|
||
SET ScriptDir=%~dp0 | ||
SET ScriptDir=%ScriptDir:~0,-1% | ||
"%ScriptDir%\pyenv-win-venv.bat" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Alias for pyenv-win-venv.ps1 | ||
&"$HOME\.pyenv-win-venv\bin\pyenv-win-venv.ps1" @args | ||
&"$PSScriptRoot\pyenv-win-venv.ps1" @args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
@ECHO OFF | ||
powershell -File "%USERPROFILE%\.pyenv-win-venv\bin\pyenv-win-venv.ps1" %* | ||
@REM Determine script location for Windows Batch File | ||
|
||
@REM Get current folder with no trailing slash | ||
SET ScriptDir=%~dp0 | ||
SET ScriptDir=%ScriptDir:~0,-1% | ||
|
||
powershell -File "%ScriptDir%\pyenv-win-venv.ps1" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# cSpell: disable | ||
# This script is based on https://github.com/Moeologist/scoop-completion | ||
|
||
# powershell completion for pyenv-win-venv | ||
|
||
###-start-pyenv-venv-completion-### | ||
$script:PyenvVenvCommands = @( | ||
'activate', | ||
'deactivate', | ||
'init', | ||
'install', | ||
'config', | ||
'completion', | ||
'list' | ||
'local', | ||
'uninstall', | ||
'update self', | ||
'which', | ||
'help' | ||
) | ||
|
||
$script:PyenvVenvSubCommands = @{ | ||
init = 'root' | ||
list = 'envs python' | ||
which = 'python python3 pip pip3' | ||
help = 'activate completion init install list uninstall which' | ||
} | ||
|
||
function script:PyenvVenvExpandCmd($filter) { | ||
$cmdList = @() | ||
$cmdList += $PyenvVenvCommands | ||
$cmdList -like "$filter*" | ||
} | ||
|
||
function script:PyenvVenvEnvNames($filter, $activate) { | ||
if ($activate) { | ||
@( pyenv-venv list envs | Where-Object { $_ -like "$filter*" }) | ||
} else { | ||
@( pyenv-venv list envs | Where-Object { $_ -like "$filter*" }) + "self" | ||
} | ||
} | ||
|
||
function script:PyenvVenvPythonVersions($filter) { | ||
@(& Get-ChildItem -Path "$env:PYENV_HOME\versions" -Name | Where-Object { $_ -like "$filter*" }) | ||
} | ||
|
||
function script:PyenvVenvExpandCmdParams($commands, $command, $filter) { | ||
$commands.$command -split ' ' | Where-Object { $_ -like "$filter*" } | ||
} | ||
|
||
function script:PyenvVenvTabExpansion($lastBlock) { | ||
switch -regex ($lastBlock) { | ||
# pyenv-venv uninstall <env_name>|self | ||
"^uninstall\s+(?:.+\s+)?(?<env_name>[\w][\-\.\w]*)?$" { | ||
return PyenvVenvEnvNames $matches['env_name'] $false | ||
} | ||
|
||
# pyenv-venv activate <env_name> | ||
"^activate\s+(?:.+\s+)?(?<env_name>[\w][\-\.\w]*)?$" { | ||
return PyenvVenvEnvNames $matches['env_name'] $true | ||
} | ||
|
||
# pyenv-venv install <python_version> <env_name> | ||
"^install\s+(?:.+\s+)?(?<python_version>[\w][\-\.\w]*)?$" { | ||
return PyenvVenvPythonVersions $matches['python_version'] | ||
} | ||
|
||
# pyenv-venv <cmd> | ||
"^(?<cmd>\S*)$" { | ||
return PyenvVenvExpandCmd $matches['cmd'] $true | ||
} | ||
|
||
# pyenv-venv <cmd> <subcmd> | ||
"^(?<cmd>$($PyenvVenvSubCommands.Keys -join '|'))\s+(?<op>\S*)$" { | ||
return PyenvVenvExpandCmdParams $PyenvVenvSubCommands $matches['cmd'] $matches['op'] | ||
} | ||
} | ||
} | ||
|
||
$scriptBlock = { | ||
param($wordToComplete, $commandAst, $cursorPosition) | ||
$rest = $commandAst.CommandElements[1..$commandAst.CommandElements.Count] -join ' ' | ||
if ($rest -ne "" -and $wordToComplete -eq "") { | ||
$rest += " " | ||
} | ||
PyenvVenvTabExpansion $rest | ||
} | ||
|
||
Register-ArgumentCompleter -Native -CommandName @('pyenv-venv', 'pyenv-win-venv') -ScriptBlock $scriptBlock | ||
|
||
###-end-pyenv-venv-completion-### |