Initial msg utility

This can replace xdg-open.
This commit is contained in:
Emery Hemingway 2022-06-09 12:24:02 -05:00
parent 724cbe68e1
commit 9b4710ea66
4 changed files with 31 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
http_translator
json_translator
msg

View File

@ -9,3 +9,8 @@ See [http_translator.config-example.pr](./http_translator.config-example.pr) for
## json_translator
Wrapper that executes a command, parses its JSON output, and asserts a Preserves conversion in an `<output …>` record.
## msg
A utility that sends a message to $SYNDICATE_SOCK in the form `<ARGV…>`.

24
src/msg.nim Normal file
View File

@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: ☭ 2022 Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[asyncdispatch, os]
from std/sequtils import map
import preserves, syndicate, syndicate/capabilities
proc unixSocketPath: string =
result = getEnv("SYNDICATE_SOCK")
if result == "":
result = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
proc mintCap: SturdyRef =
var key: array[16, byte]
mint(key, "syndicate")
bootDataspace("main") do (root: Ref; turn: var Turn):
let label = getAppFilename().extractFilename
connectUnix(turn, unixSocketPath(), mintCap()) do (turn: var Turn; ds: Ref):
var a = initRecord[Ref](label, commandLineParams().toPreserve(Ref))
message(turn, ds, a)
for i in 0..7: poll(20)
# A hack to exit

View File

@ -5,7 +5,7 @@ author = "Emery Hemingway"
description = "Utilites for Syndicated Actors and Synit"
license = "unlicense"
srcDir = "src"
bin = @["http_translator", "json_translator"]
bin = @["http_translator", "json_translator", "msg"]
# Dependencies