-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuiltin.lua
More file actions
331 lines (329 loc) · 8.11 KB
/
builtin.lua
File metadata and controls
331 lines (329 loc) · 8.11 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
---@class BuiltinCommandsModule
---@field commands table: a set of builtin commands
local M = {}
M.commands = {
{
name = "Base64 Encode (base64)",
cmd = [[%!base64]],
preview = true,
},
{
name = "Base64 Encode without newlines (tr, base64)",
cmd = [[%!tr -d '\n' | base64]],
preview = true,
},
{
name = "Base64 Decode (base64)",
cmd = [[%!base64 -d]],
preview = true,
},
{
name = "Base32 Encode (python)",
cmd = [[silent%!python -c 'import sys; import base64; print(base64.b32encode(sys.stdin.read()[:-1].encode()).decode())']],
preview = true,
},
{
name = "Base32 Decode (python)",
cmd = [[silent%!python -c 'import sys; import base64; print(base64.b32decode(sys.stdin.read()[:-1]).decode())']],
preview = true,
},
{
name = "Format JSON (jq)",
cmd = [[silent%!jq]],
preview = true,
},
{
name = "URL Encode (jq)",
cmd = [[silent%!jq -sRr @uri]],
preview = true,
},
{
name = "URL Decode (python)",
cmd = [[%!python -c 'import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read()[:-1]), end="")']],
preview = true,
},
{
name = "HTML Decode (python)",
cmd = [[%!python -c 'import sys; import html; print(html.unescape(sys.stdin.read()[:-1]))']],
preview = true,
},
{
name = "HTML Encode (python)",
cmd = [[%!python -c 'import sys; import html; print(html.escape(sys.stdin.read()[:-1]))']],
preview = true,
},
{
name = "Minify JSON (jq)",
cmd = [[silent%!jq -r tostring]],
preview = true,
},
{
name = "Minify and escape JSON (jq)",
cmd = [[silent%!jq "tostring"]],
preview = true,
},
{
name = "Unescape JSON (jq)",
cmd = [[silent%!jq fromjson]],
preview = true,
},
{
name = "Build MD5 (md5)",
cmd = [[%!md5]],
preview = true,
},
{
name = "Build SHA1 (tr, sha1sum)",
cmd = [[%!tr -d '\n' | sha1sum]],
preview = true,
},
{
name = "Build SHA256 (tr, sha256sum)",
cmd = [[%!tr -d '\n' | sha256sum]],
preview = true,
},
{
name = "Build SHA512 (tr, sha512sum)",
cmd = [[%!tr -d '\n' | sha512sum]],
preview = true,
},
{
name = "Reverse each line (rev)",
cmd = [[%!rev]],
preview = true,
},
{
name = "Reverse the order of lines (tac)",
cmd = [[%!tac]],
preview = true,
},
{
name = "Remove all whitespace (tr)",
cmd = [[%!tr -d "[:space:]"]],
preview = true,
},
{
name = "Remove blank/empty lines (grep)",
cmd = [[%!grep .]],
preview = true,
},
{
name = "Remove blank/empty lines with spaces only (grep)",
cmd = [[%!grep "\S"]],
preview = true,
},
{
name = "Remove blank/empty lines (rg)",
cmd = [[%!rg -N .]],
preview = true,
},
{
name = "Remove blank/empty lines with spaces only (rg)",
cmd = [[%!rg -N "\S"]],
preview = true,
},
{
name = "Remove blank/empty lines (vim)",
cmd = [[silent%s/\s*\n//]],
preview = true,
},
{
name = "Join lines with comma (vim)",
cmd = [[silent%s/\n/,/]],
preview = true,
},
{
name = "Join lines (vim)",
cmd = [[%j]],
preview = true,
},
{
name = "Wrap numbers with single quotes (vim)",
cmd = [[silent%s/\(\d*\)/'\1'/g]],
preview = true,
},
{
name = "Wrap numbers with double quotes (vim)",
cmd = [[silent%s/\(\d*\)/"\1"/g]],
preview = true,
},
{
name = "Wrap each line with single quotes (vim)",
cmd = [[silent%s/\(.*\)/'\1'/]],
preview = true,
},
{
name = "Wrap each line with double quotes (vim)",
cmd = [[silent%s/\(.*\)/"\1"/]],
preview = true,
},
{
name = "Remove single quotes (vim)",
cmd = [[silent%s/'//g]],
preview = true,
},
{
name = "Remove double quotes (vim)",
cmd = [[silent%s/'//g]],
preview = true,
},
{
name = "Remove duplicate lines (vim)",
cmd = [[sort u]],
preview = true,
},
{
name = "Remove duplicate lines (sort, uniq)",
cmd = [[%!sort | uniq -u]],
preview = true,
},
{
name = "Query string to json (python)",
cmd = [[silent%!python -c 'import sys; from urllib.parse import parse_qs; import json; print(json.dumps(parse_qs(sys.stdin.read()[:-1])))']],
preview = true,
},
{
name = "Sum all (awk)",
cmd = [[%!awk '{s+=$1} END {print s}']],
preview = true,
},
{
name = "Python dict to JSON (python)",
cmd = [[silent%!python -c 'import sys; import json; print(json.dumps(sys.stdin.read()[:-1]))]],
preview = true,
},
{
name = "Replace commas with newlines (vim)",
cmd = [[silent!%s/,\s*/\r/g]],
preview = true,
},
{
name = "Ansible Vault Encrypt (ansible-vault)",
cmd = [[silent%!ansible-vault encrypt]],
preview = true,
},
{
name = "Ansible Vault Decrypt (ansible-vault)",
cmd = [[silent%!ansible-vault decrypt]],
preview = true,
},
{
name = "PowerShell escape characters to Unix (vim)",
cmd = function()
vim.cmd([[silent!%s/\^$/\\/]])
vim.cmd([[silent!%s/\^\\\^/\\/g]])
end,
preview = true,
},
{
name = "Change single quotes to double quotes (vim)",
cmd = [[silent!%s/'/"/g]],
preview = true,
},
{
name = "Change double quotes to single quotes (vim)",
cmd = [[silent!%s/"/'/g]],
preview = true,
},
{
name = "snake_case to CamelCase (python)",
cmd = [[silent%!python -c 'import sys; print("".join(map(lambda x: x[0].upper() + x[1:], sys.stdin.read()[:-1].split("_"))))']],
preview = true,
},
{
name = "CamelCase to snake_case (python)",
cmd = [[silent%!python -c 'import sys; print("".join(map(lambda y: f"_{y.lower()}" if y.isupper() else y, [ z for z in sys.stdin.read()[:-1] ]))[1:])']],
preview = true,
},
{
name = "snake_case to kebab-case (python)",
cmd = [[silent%!python -c 'import sys; print(sys.stdin.read()[:-1].replace("_", "-"))']],
preview = true,
},
{
name = "kebab-case to snake_case (python)",
cmd = [[silent%!python -c 'import sys; print(sys.stdin.read()[:-1].replace("-", "_"))']],
preview = true,
},
{
name = "To UPPER case (python)",
cmd = [[silent%!python -c 'import sys; print(sys.stdin.read()[:-1].upper())']],
preview = true,
},
{
name = "To lower case (python)",
cmd = [[silent%!python -c 'import sys; print(sys.stdin.read()[:-1].lower())']],
preview = true,
},
{
name = "Generate UUID4 (python)",
cmd = [[silent%!python -c 'import uuid; print(uuid.uuid4())']],
preview = true,
},
{
name = "Unix timestamp to ISO formatted datetime (python)",
cmd = [[silent%!python -c 'import sys; from datetime import datetime; print(datetime.utcfromtimestamp(int(sys.stdin.read()[:-1])).isoformat())']],
preview = true,
},
{
name = "ISO formatted datetime to Unix timestamp (python)",
cmd = [[silent%!python -c 'import sys; from datetime import datetime; print(int(datetime.fromisoformat(sys.stdin.read()[:-1]).timestamp()))']],
preview = true,
},
{
name = "Shuffle lines (shuf)",
cmd = [[silent%!shuf]],
preview = true,
},
{
name = "Sort JSON keys (jq)",
cmd = [[silent%!jq --sort-keys]],
preview = true,
},
{
name = "Add comma at the end of each line (vim)",
cmd = [[silent%s/$/,\r/]],
preview = true,
},
{
name = "Remove whitespace on each line (vim)",
cmd = [[silent!%s/\s//]],
preview = true,
},
{
name = "JSON to CSV (dasel)",
cmd = [[silent%!dasel -r json -w csv]],
preview = true,
},
{
name = "CSV to JSON (dasel)",
cmd = [[silent%!dasel -r csv -w json]],
preview = true,
},
{
name = "JSON to YAML (dasel)",
cmd = [[silent%!dasel -r json -w yaml]],
preview = true,
},
{
name = "YAML to JSON (dasel)",
cmd = [[silent%!dasel -r yaml -w json]],
preview = true,
},
{
name = "YAML to CSV (dasel)",
cmd = [[silent%!dasel -r yaml -w csv]],
preview = true,
},
{
name = "CSV to YAML (dasel)",
cmd = [[silent%!dasel -r csv -w yaml]],
preview = true,
},
{
name = "Insert whatthecommit.com message (curl)",
cmd = [[r!curl -s https://whatthecommit.com/index.txt]],
preview = false,
},
}
return M