Initial commit.
This commit is contained in:
59
Modules/posh-nodejs/posh-nodejs.psm1
Normal file
59
Modules/posh-nodejs/posh-nodejs.psm1
Normal 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]}."
|
||||
}
|
||||
}
|
||||
}
|
20
Modules/posh-ssh/posh-ssh.psm1
Normal file
20
Modules/posh-ssh/posh-ssh.psm1
Normal 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 {
|
||||
"$_"
|
||||
}
|
||||
}
|
54
Modules/posh-venv/posh-venv.psm1
Normal file
54
Modules/posh-venv/posh-venv.psm1
Normal 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]}."
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user