Skip to content

Instantly share code, notes, and snippets.

@sixeyed
Created November 1, 2018 11:25
Show Gist options
  • Select an option

  • Save sixeyed/c3ae1fd8033b8208ad29458a56856e05 to your computer and use it in GitHub Desktop.

Select an option

Save sixeyed/c3ae1fd8033b8208ad29458a56856e05 to your computer and use it in GitHub Desktop.

Revisions

  1. sixeyed created this gist Nov 1, 2018.
    40 changes: 40 additions & 0 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    function Prompt(){
    $W = Split-Path -leaf -path (Get-Location)
    $prompt = Write-Prompt "$($env:UserName)@$($env:ComputerName):" -ForegroundColor Green
    $prompt += Write-Prompt $W -ForegroundColor DarkCyan
    $prompt += Write-Prompt '>'
    return ' '
    }

    function Remove-StoppedContainers {
    docker container rm $(docker container ls -q)
    }

    function Remove-AllContainers {
    docker container rm -f $(docker container ls -aq)
    }

    function Get-ContainerIPAddress {
    param (
    [string] $id
    )
    & docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' $id
    }

    function Add-ContainerIpToHosts {
    param (
    [string] $name
    )
    $ip = docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' $name
    $newEntry = "$ip $name #added by d2h# `r`n"
    $path = 'C:\Windows\System32\drivers\etc\hosts'
    $newEntry + (Get-Content $path -Raw) | Set-Content $path
    }

    Set-Alias drm Remove-StoppedContainers

    Set-Alias drmf Remove-AllContainers

    Set-Alias dip Get-ContainerIPAddress

    Set-Alias d2h Add-ContainerIpToHosts