Home

dotnix @main - refs - log -
-
https://git.jolheiser.com/dotnix.git
My nix dotfiles
tree log patch
tangled string cli Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQKn85PrSxTTShsfuKiuBydBLvrFeeUQqEBdLGimIkV8H7EQdBWjVg/9qpPzDy41u7H OVnJOTDzo9aizAmYpERgo= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
1 week ago
3 changed files, 55 additions(+), 0 deletions(-)
apps/nogui/nushell.nixapps/nogui/nushell/jolheiser.nuapps/nogui/nushell/tangled.nu
M apps/nogui/nushell.nixapps/nogui/nushell.nix
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
diff --git a/apps/nogui/nushell.nix b/apps/nogui/nushell.nix
index 2db332f10de911301df90a8112636d640532f7d3..53a11fe1cea4e81a534e3374256b656f22c87630 100644
--- a/apps/nogui/nushell.nix
+++ b/apps/nogui/nushell.nix
@@ -36,5 +36,6 @@     "nushell/miniserve.nu".source = ./nushell/miniserve.nu;
     "nushell/clone.nu".source = ./nushell/clone.nu;
     "nushell/git-bug.nu".source = ./nushell/git-bug.nu;
     "nushell/ohmyposh.nu".source = ./nushell/ohmyposh.nu;
+    "nushell/tangled.nu".source = ./nushell/tangled.nu;
   };
 }
M apps/nogui/nushell/jolheiser.nuapps/nogui/nushell/jolheiser.nu
1
2
3
4
5
6
7
8
9
diff --git a/apps/nogui/nushell/jolheiser.nu b/apps/nogui/nushell/jolheiser.nu
index ca78e1333810165b32f9854664ce7b4a79209893..4bee4267c92f68640da62d8b638a49853b158dd2 100644
--- a/apps/nogui/nushell/jolheiser.nu
+++ b/apps/nogui/nushell/jolheiser.nu
@@ -64,3 +64,4 @@ source ~/.config/nushell/ssh.nu
 source ~/.config/nushell/miniserve.nu
 source ~/.config/nushell/clone.nu
 source ~/.config/nushell/git-bug.nu
+source ~/.config/nushell/tangled.nu
I apps/nogui/nushell/tangled.nu
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
diff --git a/apps/nogui/nushell/tangled.nu b/apps/nogui/nushell/tangled.nu
new file mode 100644
index 0000000000000000000000000000000000000000..7ef73c0326ff8eef5f890da57c5603680ee32c5c
--- /dev/null
+++ b/apps/nogui/nushell/tangled.nu
@@ -0,0 +1,53 @@
+# Strings CLI
+#
+# Examples:
+# $ string main.go
+# $ echo "Hey tanglers!" | string --title "tanglers.txt" --description "A file for all the tanglers"
+export def string [
+  file?:              path   # File to create string from, otherwise stdin
+  --title (-t):       string # Title of the string (default is filename when file is provided, otherwise random uuid)
+  --description (-d): string # Description of the string
+]: [
+  path -> string
+  nothing -> string
+] {
+  mut _content = $in
+  mut _title = (random uuid) 
+  if ($file != null) {
+    $_content = ($file | open --raw | decode utf-8)
+    $_title = ($file | path basename)
+  }
+  if ($title != null) {
+    $_title = $title
+  }
+  mut _desc = ""
+  if ($description != null) {
+    $_desc = $description
+  }
+
+  let payload = ({
+    "$type": "sh.tangled.string",
+    "contents": $_content,
+    "filename": $_title,
+    "createdAt": (date now | format date "%Y-%m-%dT%H:%M:%SZ"),
+    "description": $_desc
+  } | to json)
+
+  let tmp = (mktemp --tmpdir sh.tangled.string.XXX)
+  
+  $payload | save --force $tmp
+
+  mut out = ""
+  try {
+    let resp = (^goat record create --no-validate $tmp)
+    # at://did:plc:35kdk2ntcs626zs6cm62i7ih/sh.tangled.string/3lxuash7vvc2f   bafyreifv7c6il2zsa67oa6umutb52izbgrnmz336wzbgti2we3tpw3bcj4
+    # 0    1   2   3                        4  5       6      7               8
+    let plc = ($resp | split words | get 3)
+    let rkey = ($resp | split words | get 7)
+    $out = $"https://tangled.sh/strings/did:plc:($plc)/($rkey)"
+  }
+
+  rm $tmp
+
+  $out
+}