-
-
Notifications
You must be signed in to change notification settings - Fork 631
Expand file tree
/
Copy pathhelp-defaults.sh
More file actions
executable file
·63 lines (49 loc) · 1.75 KB
/
help-defaults.sh
File metadata and controls
executable file
·63 lines (49 loc) · 1.75 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
#!/usr/bin/env sh
# run after changing default config or keymap.lua M.on_attach_default
# scrapes and updates nvim-tree-lua.txt
# run from repository root: scripts/help-defaults.sh OR make help-update
set -e
#
# Operate on a temporary file as sed -i writes the file thousands of times.
#
WIP="/tmp/nvim-tree-lua.txt"
cp "doc/nvim-tree-lua.txt" "${WIP}"
#
# Inject default config
#
begin="config-default-start"
end="config-default-end"
inject="config-default-injection-placeholder"
# scrape config.default, indented at 2
sed -n -E "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree/config.lua > /tmp/config.default.2.lua
# indent to match help
sed -E "s/^ / /" /tmp/config.default.2.lua > /tmp/config.default.6.lua
# inject then remove the placeholder
sed -i -E "/${inject}/r /tmp/config.default.6.lua" "${WIP}"
sed -i -E "/${inject}/d" "${WIP}"
#
# Inject default mappings
#
begin="BEGIN_ON_ATTACH_DEFAULT"
end="END_ON_ATTACH_DEFAULT"
# scrape ON_ATTACH_DEFAULT, indented at 2
sed -n -E "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree/keymap.lua > /tmp/ON_ATTACH_DEFAULT.lua
# help lua
sed -i -E "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/ON_ATTACH_DEFAULT.lua
}; /${end}/p; d; }" "${WIP}"
# help human
echo > /tmp/ON_ATTACH_DEFAULT.help
sed -E "s/^ *vim.keymap.set\(\"n\", \"(.*)\",.*api(.*),.*opts\(\"(.*)\".*$/'\`\1\`' '\3' '|nvim_tree.api\2()|'/g
" /tmp/ON_ATTACH_DEFAULT.lua | while read -r line
do
eval "printf '%-17.17s %-26.26s %s\n' ${line}" >> /tmp/ON_ATTACH_DEFAULT.help
done
echo >> /tmp/ON_ATTACH_DEFAULT.help
begin="Show the mappings:"
end="======"
sed -i -E "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/ON_ATTACH_DEFAULT.help
}; /${end}/p; d; }" "${WIP}"
#
# complete
#
mv "${WIP}" "doc/nvim-tree-lua.txt"