Initial commit.

This commit is contained in:
Mikael CAPELLE
2022-08-16 08:43:25 +02:00
commit 18bbe73ca8
5 changed files with 320 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
if (Get-Module posh-nodejs) { return }
$NodeJsHome = "$HOME\Apps\nodejs"
$InitialNodePath = $env:Path.Split(";") | Where-Object { $_ -like "$NodeJsHome*" }
function CompleteNodeJsVersion {
param($commandName, $parameterName, $wordToComplete,
$commandAst, $fakeBoundParameters)
Get-ChildItem -Directory $NodeJsHome
| ForEach-Object { $_.Name.Split("-")[1].Substring(1) }
| Where-Object { $_ -Like "$wordToComplete*" }
| Sort-Object
}
function nvm {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateSet("list", "activate", "deactivate")]
$command,
[Parameter(Mandatory = $false)]
[ArgumentCompleter({ CompleteNodeJsVersion @args })]
$version)
switch ($command) {
"list" {
Get-ChildItem -Directory $NodeJsHome
| ForEach-Object {
$version = $_.Name.Split("-")[1].Substring(1)
Write-Output "$version"
}
}
"activate" {
$path = "$NodeJsHome\node-v$version-win-x64"
if (Test-Path "$path") {
$paths = $env:Path.Split(";") | Where-Object { $_ -NotLike "$NodeJsHome*" }
$paths += $path
$env:Path = $paths | Join-String -Separator ";"
}
else {
Write-Error "NodeJS version '${version}' not found."
}
}
"deactivate" {
$paths = $env:Path.Split(";") | Where-Object { $_ -NotLike "$NodeJsHome*" }
$paths += $InitialNodePath
$env:Path = $paths | Join-String -Separator ";"
}
default {
Write-Error "Unknown nvm command ${args[0]}."
}
}
}

View File

@@ -0,0 +1,20 @@
if (Get-Module posh-ssh) {
return
}
$cmdNames = "ssh"
$cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name
$configFile = "$env:USERPROFILE/.ssh/config"
Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
Get-Content $configFile | Select-String -Pattern "^Host(\s+([.A-Za-z0-9\-_]+))+\s*$" | ForEach-Object {
$_.Matches.Groups[2].Captures.Value
} | Where-Object {
$_ -like "$wordToComplete*"
} | ForEach-Object {
"$_"
}
}

View File

@@ -0,0 +1,54 @@
if (Get-Module posh-venv) { return }
function CompleteVenvName {
param($commandName, $parameterName, $wordToComplete,
$commandAst, $fakeBoundParameters)
Get-ChildItem -Directory $env:WORKON_HOME
| ForEach-Object { $_.Name }
| Where-Object { $_ -Like "$wordToComplete*" }
| Sort-Object
}
function venv {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateSet("list", "activate", "deactivate")]
$command,
[Parameter(Mandatory = $false)]
[ArgumentCompleter({ CompleteVenvName @args })]
$venv)
switch ($command) {
"list" {
Get-ChildItem -Directory $env:WORKON_HOME
| ForEach-Object {
$name = $_.Name
$version = (& "$_/Scripts/python.exe" --version)
Write-Output "${name}: $version"
}
}
"activate" {
if (Test-Path "$env:WORKON_HOME/$venv/Scripts/activate.ps1") {
& "$env:WORKON_HOME/$venv/Scripts/activate.ps1"
}
elseif ((!$venv -Or !$venv.Trim()) -And (Test-Path "venv/Scripts/activate.ps1")) {
& "venv/Scripts/activate.ps1"
}
else {
Write-Error "Environment '${venv}' does not exists."
}
}
"deactivate" {
deactivate
}
default {
Write-Error "Unknown venv command ${args[0]}."
}
}
}