diff --git a/tree/.config/nushell/config.nu.tpl b/tree/.config/nushell/config.nu.tpl index fe5273c..eeef2c5 100644 --- a/tree/.config/nushell/config.nu.tpl +++ b/tree/.config/nushell/config.nu.tpl @@ -682,6 +682,7 @@ alias xo = xdg-open source ~/.local/nu/readelf.nu source ~/.local/nu/mullvad.nu source ~/.local/nu/git.nu +source ~/.local/nu/tailscale.nu {% if os == "darwin" %} source ~/.local/nu/macos.nu {% end %} diff --git a/tree/.local/nu/tailscale.nu b/tree/.local/nu/tailscale.nu new file mode 100644 index 0000000..a991fc7 --- /dev/null +++ b/tree/.local/nu/tailscale.nu @@ -0,0 +1,31 @@ +def "tailscale peer" [ + hostname?: string + path?: cell-path +]: nothing -> any { + let path = ($path | default ([] | into cell-path)) + + let status = (^tailscale status --json | from json) + + let peers = ($status | get Peer | transpose key fields | flatten fields) + + let peers = ($peers | each { |peer| + let ipv4 = $peer.TailscaleIPs | where { |ip| "." in $ip } | first + let ipv6 = $peer.TailscaleIPs | where { |ip| ":" in $ip } | first + + { + host: $peer.HostName, + ipv4: $ipv4, + ipv6: $ipv6, + online: $peer.Online, + active: $peer.Active, + rx: ($peer.RxBytes | into filesize), + tx: ($peer.TxBytes | into filesize), + } + }) + + if $hostname == null { + $peers + } else { + $peers | where host == $hostname | first | get $path + } +}