-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
59 lines (51 loc) · 2.03 KB
/
install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
. "$PSScriptRoot\config.ps1"
$modulePath = ($env:PSModulePath -split ";")[0] + '\wsl-alias\wsl-alias.psm1'
$funcTemplate = @'
function \$wslcommand {
if($MyInvocation.ExpectingInput){
$input | & wsl $MyInvocation.InvocationName $args
}else{
& wsl $MyInvocation.InvocationName $args
}
}
function \$wslcolorcommand {
if($MyInvocation.ExpectingInput){
$input | & wsl $MyInvocation.InvocationName --color=auto $args
}else{
& wsl $MyInvocation.InvocationName --color=auto $args
}
}
'@
$ToWslPathFunction = @'
function ToWslPath ($path) {
if (-not (Test-Path $path)) { return $path }
if (Split-Path $path -IsAbsolute) {
$path = "/mnt/" + (Split-Path $path -Qualifier).Replace(":", "").ToLower() + (Split-Path $path -NoQualifier)
}
return $path.Replace("\", "/")
}
'@
Remove-Module wsl-alias -Force 2>$null
Set-Location $PSScriptRoot
New-Item $modulePath -Force
if ($convertPath) {
$ToWslPathFunction | Out-File $modulePath -Encoding ascii -Append
$funcTemplate = $funcTemplate.Replace('$args', '($args | ForEach-Object{ToWslPath $_})')
}
$funcTemplate | Out-File $modulePath -Encoding ascii -Append
$commands = if ($whiteList) {$whiteList} else {& wsl sh get_command.sh}
$commands = $commands | Where-Object { $blackList -notcontains $_ }
if (-not $overrideDefault) { $commands = $commands | Where-Object { -not(Test-Path alias:$_) } }
$setAliasCommands = [System.Collections.Generic.List[string]]::new()
foreach ($name in $commands) {
if ($autoColorCommands -contains $name) {
$setAliasCommands.Add('Set-Alias {0} ''\$wslcolorcommand''' -f $name)
}
else {
$setAliasCommands.Add('Set-Alias {0} ''\$wslcommand''' -f $name)
}
Write-Host $name
}
$setAliasCommands | Out-File $modulePath -Encoding ascii -Append
New-ModuleManifest $modulePath.Replace('.psm1', '.psd1') -RootModule 'wsl-alias.psm1' -Author 'naminodarie' -ModuleVersion '0.1' -FunctionsToExport 'ToWslPath', '\$wslcommand', '\$wslcolorcommand' -AliasesToExport $commands
Import-Module wsl-alias