Bash.psm1
Function Invoke-BashCommand { Bash -c "$($MyInvocation.InvocationName) $Args" } Function Add-BashCommand { Param( [Parameter( Mandatory = $True )] [String] $Command ) Set-Alias -Name $Command -Value Invoke-BashCommand -Scope Global -ErrorAction Stop $Content = "Set-Alias -Name $Command -Value Invoke-BashCommand" If (-Not (Test-Path -PathType Leaf -Path $Profile)) { Set-Content -Path $Profile -Value $Content } Else { If (-Not (Get-Content -Path $Profile | Select-String $Content)) { Add-Content -Path $Profile -Value $Content } } } Function Remove-BashCommand { Param( [Parameter( Mandatory = $True )] [String] $Command ) Remove-Item Alias:$Command If (Test-Path -PathType Leaf -Path $Profile) { $Content = Get-Content -Path $Profile | Select-String -NotMatch -Pattern "Set-Alias -Name $Command -Value Invoke-BashCommand" Set-Content -Path $Profile -Value $Content } } Function Get-BashCommand { Param( [String] $Command ) If ($Command) { If (Get-Content -Path $Profile | Select-String -Pattern "Set-Alias -Name $Command -Value Invoke-BashCommand") { $Command } } Else { $MatchesCommands = Get-Content -Path $Profile | Select-String -Pattern "Set-Alias -Name (\w+) -Value Invoke-BashCommand" ForEach ($Match in $MatchesCommands.Matches) { Write-Output $Match.Groups[1].Value } } } |