Home

dotnix @7e1647b69a87fbd905730f91ab33191e8ec6ffca - refs - log -
-
https://git.jolheiser.com/dotnix.git
My nix dotfiles
dotnix / apps / nogui / nushell / tangled.nu
- raw -
 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
# 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
  }

  if ($_content == null or $_content == "") {
    error make {msg: "Cannot create a string with no content"}
  }

  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
}