-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnminis
More file actions
executable file
·104 lines (91 loc) · 1.98 KB
/
nminis
File metadata and controls
executable file
·104 lines (91 loc) · 1.98 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
# alias fzf="fzy"
dm_fetch_save() {
if [ "$#" -lt 1 ]; then
echo "error: insert inbox relays" >&2
return 1
fi
inbox_relays="$1"
shift 1
if [ "$#" -lt 1 ]; then
echo "error: insert save dir" >&2
return 1
fi
save_dir="$1"
shift 1
if [ -t 0 ]; then
echo "error: insert private key in stdin" >&2
return 1
fi
private_key="$(cat)"
public_key="$(printf "%s\n" "$private_key" | nmini key-convert phex)"
fetched_messages="$(
printf "%s\n" "$private_key" |
nmini dm-fetch "$inbox_relays"
)"
if warnings="$(
printf "%s\n" "$fetched_messages" |
jq -e '.warning' 2>/dev/null
)"; then
printf "%s\n" "$warnings" >&2
fi
printf "%s\n" "$fetched_messages" |
nmini dm-save "$public_key" "$save_dir"
}
chat_show() {
if [ "$#" -lt 1 ]; then
echo "error: insert peer dir" >&2
return 1
fi
peer_dir="$1"
shift 1
find "$peer_dir" -mindepth 1 -maxdepth 1 -type f |
sort -n |
xargs -I '{}' cat '{}' |
jq -r '. | "[\(.created_at.date)] \(.pubkey.bech32[4:8]) | \(.content)"'
}
chat_find_show() {
if [ "$#" -lt 1 ]; then
echo "error: insert base dir" >&2
return 1
fi
base_dir="$1"
shift 1
peer="$(
find "$base_dir" -mindepth 1 -maxdepth 1 -type d -exec basename '{}' \; |
fzf
)"
chat_show "$base_dir/$peer"
}
info=$(cat << EOF
nminis action [options]
<private-key> | dm-fetch-save <inbox-relays> <dir>
chat-show <peer-dir>
chat-find-show <dir>
EOF
)
if [ "$#" -lt 1 ]; then
echo "error: insert arguments" >&2
exit 1
fi
action="$1"
shift 1
case "$action" in
-h|--help)
echo "$info"
exit 0
;;
dm-fetch-save)
dm_fetch_save "$@"
;;
chat-show)
chat_show "$@"
;;
chat-find-show)
chat_find_show "$@"
;;
*)
echo "error: action $action not found" >&2
exit 1
;;
esac