add hwylterm

This commit is contained in:
Daylin Morgan 2024-10-08 12:15:53 -05:00
parent cae07a51f4
commit 588d763930
Signed by: daylin
GPG key ID: 950D13E9719334AD
5 changed files with 25 additions and 14 deletions

View file

@ -1,6 +1,5 @@
{
lib,
makeWrapper,
buildNimblePackage,
}:
buildNimblePackage {
@ -8,7 +7,6 @@ buildNimblePackage {
version = "unstable";
src = lib.cleanSource ./.;
nativeBuildInputs = [ makeWrapper ];
doCheck = false;
nimbleDepsHash = "sha256-fw0Utdq5wu2t30hez6EWgulzieIMlE07bOpYdtL6nms=";
nimbleDepsHash = "sha256-2yuYtCq4nqwXlWA02RhoScfGprEVdZkxoaVSWPH0eL8=";
}

View file

@ -10,6 +10,16 @@
"checksums": {
"sha1": "5a082835594887c0fdaea17dbfd2d3a2e744a2a9"
}
},
"hwylterm": {
"version": "0.1.0",
"vcsRevision": "7e82f7ba5a24d816a79b3a5ea49f32b4c7a5ef7e",
"url": "https://github.com/daylinmorgan/hwylterm",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "d6d97bdff3fcdfcf4b39b144fa5f27a6b9f9494d"
}
}
},
"tasks": {}

View file

@ -1,5 +1,5 @@
# tunnel-nim todo's
- [ ] show no output from tunnel up on connection
- [ ] show no output from `tunnel up` on connection
<!-- generated with <3 by daylinmorgan/todo -->

View file

@ -1,11 +1,12 @@
import std/[os, osproc, sequtils, strformat, strutils, sugar]
import cligen
import hwylterm
proc checkHost(host: seq[string]): string =
case host.len:
of 1: return host[0]
of 0: quit "expected hostname"
else: quit "expected one positinal argument"
of 0: quit $bb"[red]expected hostname"
else: quit $bb"[red]expected one positional argument"
proc check(name: string): bool = (execCmd &"ssh -O check {name}") == 0
proc startSsh(name: string) = discard execCmd &"ssh -M -f -N {name}"
@ -33,13 +34,15 @@ proc show() =
collect(for _,p in walkDir(sshDir): p)
.map(extractFilename)
.filterIt(it.startsWith("control"))
echo &"{controllers.len} active connections"
echo fmt"[yellow]{controllers.len}[/] active connections"
if controllers.len == 0: quit 0
echo "hosts:"
echo controllers.mapIt(" " & it.split('-')[1]).join("\n")
const
hostUsage = "$command [flags] hostname\n${doc}Options:\n$options"
usage = "$command [flags]\n${doc}Options:\n$options"
dispatchMulti([up, usage=hostUsage], [down, usage=hostUsage], [show, usage=usage])
when isMainModule:
import cligen, hwylterm/cligen
hwylCli(clCfg)
let
# use= $bb("$command [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options")
hostUse= $bb("$command [green]hostname[/] [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options")
dispatchMulti([up,usage=hostUse], [down, usage=hostUse], [show, usage=clCfg.use])

View file

@ -11,5 +11,5 @@ bin = @["tunnel"]
# Dependencies
requires "nim >= 2.0.8"
requires "cligen"
requires "https://github.com/daylinmorgan/hwylterm#HEAD"