completions/ping.ps1

<#
 # ping completion
 #>

Import-Module NativeCommandCompleter.psm -ErrorAction SilentlyContinue

$msg = data { ConvertFrom-StringData @'
    ping = Send ICMP ECHO_REQUEST packets to network hosts

    win_continuous = Continue sending echo Request messages
    win_resolve = Resolve addresses to hostnames
    win_count = Number of echo requests to send
    win_size = Send buffer size
    win_fragment = Don't fragment flag in packet (IPv4-only)
    win_ttl = Set Time To Live
    win_sourceAddr = Specifies the source address to use (available on IPv6 only).
    win_recordRoute = Record route for count hops (IPv4-only)
    win_timestamp = Timestamp for count hops (IPv4-only)
    win_timeout = Timeout in milliseconds to wait for each reply
    win_looseHostList = Loose source route along host-list (IPv4-only)
    win_strictHostList = Strict source route along host-list (IPv4-only)
    win_typeOfService = Type Of Service (IPv4-only)
    win_roundTrip = Specifies the round-trip path is traced (available on IPv6 only).
    win_compartment = Routing compartment identifier

    audible = Audible ping
    adaptive = Adaptive ping
    broadcast = Allow pinging a broadcast address (IPv4 only)
    stickySrcAddr = Sticky source address
    count = Stop after sending count ECHO_REQUEST packets
    printTimestamp = Print timestamps
    soDebug = Set SO_DEBUG socket option
    flood = Flood ping
    interface = Set source address to specified interface address
    interval = Wait interval seconds between sending each packet
    preload = Send preload number of packets as fast as possible
    numeric = Numeric output only
    pattern = Specify up to 16 padding bytes to fill out the packet
    quiet = Quiet output
    bypassRouting = Bypass the normal routing tables
    recordRoute = Record route
    size = Specifies the number of data bytes to be sent
    timestamp = Set IP timestamp options (IPv4 only)
    ttl = Set the IP Time to Live
    u2uLatency = Print full user-to-user latency
    verbose = Verbose output
    timeout = Time to wait for a response, in seconds
    deadline = Specify a timeout, in seconds, before ping exits
    version = Show version and exit
    help = Display help and exit
    ipv4 = Use IPv4 only
    ipv6 = Use IPv6 only
    mark = Tag the packets going out
    socketBufSz = Set socket buffer size
    mtu_discovery = Set Path MTU Discovery strategy
    pmtudisc_do = Prohibit fragmentation
    pmtudisc_dont = Do not set DF flag
    pmtudisc_want = Do PMTU discovery, fragment locally when needed
    pmtudisc_probe = Do PMTU discovery, do not fragment
'@
 }
Import-LocalizedData -BindingVariable localizedMessages -ErrorAction SilentlyContinue;
foreach ($key in $localizedMessages.Keys) { $msg[$key] = $localizedMessages[$key] }

if ($IsWindows)
{
    $style = New-ParamStyle -ValueStyle Separated

    Register-NativeCompleter -Name ping -Description $msg.ping -Parameters @(
        New-ParamCompleter -Name '-t','/t' -Style $style -Description $msg.win_continuous
        New-ParamCompleter -Name '-a','/a' -Style $style -Description $msg.win_resolve
        New-ParamCompleter -Name '-n','/n' -Style $style -Description $msg.win_count -Arguments @{ Name = 'count' }
        New-ParamCompleter -Name '-l','/l' -Style $style -Description $msg.win_size -Arguments @{ Name = 'size' }
        New-ParamCompleter -Name '-f','/f' -Style $style -Description $msg.win_fragment
        New-ParamCompleter -Name '-i','/i' -Style $style -Description $msg.win_ttl -Arguments @{ Name = 'TTL' }
        New-ParamCompleter -Name '-v','/v' -Style $style -Description $msg.win_typeOfService -Arguments @{ Name = 'TOS' }
        New-ParamCompleter -Name '-r','/r' -Style $style -Description $msg.win_recordRoute -Arguments @{ Name = 'count' }
        New-ParamCompleter -Name '-s','/s' -Style $style -Description $msg.win_timestamp -Arguments @{ Name = 'count' }
        New-ParamCompleter -Name '-j','/j' -Style $style -Description $msg.win_looseHostList -Arguments @{ Name = 'host-list' }
        New-ParamCompleter -Name '-k','/k' -Style $style -Description $msg.win_strictHostList -Arguments @{ Name = 'host-list' }
        New-ParamCompleter -Name '-w','/w' -Style $style -Description $msg.win_timeout -Arguments @{ Name = 'timeout' }
        New-ParamCompleter -Name '-R','/R' -Style $style -Description $msg.win_roundTrip
        New-ParamCompleter -Name '-S','/S' -Style $style -Description $msg.win_sourceAddr -Arguments @{ Name = 'src-addr' }
        New-ParamCompleter -Name '-c','/c' -Style $style -Description $msg.win_compartment -Arguments @{ Name = 'compartment' }
        New-ParamCompleter -Name '-4','/4' -Style $style -Description $msg.ipv4
        New-ParamCompleter -Name '-6','/6' -Style $style -Description $msg.ipv6
        New-ParamCompleter -Name '-?','/?' -Style $style -Description $msg.help
    ) -NoFileCompletions
    return
}
else
{
    Register-NativeCompleter -Name ping -Style Unix -Description $msg.ping -Parameters @(
        New-ParamCompleter -ShortName a -Description $msg.audible
        New-ParamCompleter -ShortName A -Description $msg.adaptive
        New-ParamCompleter -ShortName b -Description $msg.broadcast
        New-ParamCompleter -ShortName B -Description $msg.stickySrcAddr
        New-ParamCompleter -ShortName c -Description $msg.count -Arguments @{ Name = 'count' }
        New-ParamCompleter -ShortName D -Description $msg.printTimestamp
        New-ParamCompleter -ShortName d -Description $msg.soDebug
        New-ParamCompleter -ShortName f -Description $msg.flood
        New-ParamCompleter -ShortName i -Description $msg.interval -Arguments @{ Name = 'interval' }
        New-ParamCompleter -ShortName I -Description $msg.interface -Arguments @{ Name = 'interface' }
        New-ParamCompleter -ShortName l -Description $msg.preload -Arguments @{ Name = 'preload' }
        New-ParamCompleter -ShortName m -Description $msg.mark -Arguments @{ Name = 'mark' }
        New-ParamCompleter -ShortName M -Description $msg.mtu_discovery -Arguments @{
            Name = 'pmtudisc_opt'; Candidates = @(
                "do`t{0}" -f $msg.pmtudisc_do
                "dont`t{0}" -f $msg.pmtudisc_dont
                "want`t{0}" -f $msg.pmtudisc_want
                "probe`t{0}" -f $msg.pmtudisc_probe
            )
        }
        New-ParamCompleter -ShortName n -Description $msg.numeric
        New-ParamCompleter -ShortName p -Description $msg.pattern -Arguments @{ Name = 'pattern' }
        New-ParamCompleter -ShortName q -Description $msg.quiet
        New-ParamCompleter -ShortName r -Description $msg.bypassRouting
        New-ParamCompleter -ShortName R -Description $msg.recordRoute
        New-ParamCompleter -ShortName s -Description $msg.size -Arguments @{ Name = 'packetsize' }
        New-ParamCompleter -ShortName S -Description $msg.socketBufSz -Arguments @{ Name = 'sndbuf' }
        New-ParamCompleter -ShortName t -Description $msg.ttl -Arguments @{ Name = 'ttl' }
        New-ParamCompleter -ShortName T -Description $msg.timestamp -Arguments @{ Name = 'timestamp_opt'; Candidates = "tsonly","tsandaddr","tsprespec" }
        New-ParamCompleter -ShortName U -Description $msg.u2uLatency
        New-ParamCompleter -ShortName v -Description $msg.verbose
        New-ParamCompleter -ShortName V -Description $msg.version
        New-ParamCompleter -ShortName w -Description $msg.deadline -Arguments @{ Name = 'deadline' }
        New-ParamCompleter -ShortName W -Description $msg.timeout -Arguments @{ Name = 'timeout' }
        New-ParamCompleter -ShortName '4' -Description $msg.ipv4
        New-ParamCompleter -ShortName '6' -Description $msg.ipv6
        New-ParamCompleter -ShortName h -Description $msg.help
    ) -NoFileCompletions
}