doc: default mappings
This commit is contained in:
committed by
GitHub
parent
5e900c2f29
commit
8198fa01fc
104
scripts/generate_default_mappings.lua
Normal file
104
scripts/generate_default_mappings.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
-- luacheck:ignore 113
|
||||
---@diagnostic disable: undefined-global
|
||||
|
||||
-- write DEFAULT_MAPPINGS in various formats
|
||||
|
||||
local max_key_help = 0
|
||||
local max_key_lua = 0
|
||||
local max_action_help = 0
|
||||
local outs_help = {}
|
||||
local outs_lua = {}
|
||||
|
||||
for _, m in pairs(M.mappings) do
|
||||
local out
|
||||
if type(m.key) == "table" then
|
||||
local first = true
|
||||
local keys_lua = "key = {"
|
||||
for _, sub_key in pairs(m.key) do
|
||||
-- lua
|
||||
keys_lua = string.format('%s%s "%s"', keys_lua, first and "" or ",", sub_key)
|
||||
|
||||
-- help
|
||||
out = {}
|
||||
if first then
|
||||
out.action = m.action
|
||||
out.desc = m.desc
|
||||
first = false
|
||||
else
|
||||
out.action = ""
|
||||
out.desc = ""
|
||||
end
|
||||
out.key = string.format("`%s`", sub_key)
|
||||
max_action_help = math.max(#out.action, max_action_help)
|
||||
max_key_help = math.max(#out.key, max_key_help)
|
||||
table.insert(outs_help, out)
|
||||
end
|
||||
|
||||
-- lua
|
||||
out = {}
|
||||
out.key = string.format("%s },", keys_lua)
|
||||
table.insert(outs_lua, out)
|
||||
else
|
||||
-- help
|
||||
out = {}
|
||||
out.action = m.action
|
||||
out.desc = m.desc
|
||||
out.key = string.format("`%s`", m.key)
|
||||
table.insert(outs_help, out)
|
||||
max_action_help = math.max(#out.action, max_action_help)
|
||||
max_key_help = math.max(#out.key, max_key_help)
|
||||
|
||||
-- lua
|
||||
out = {}
|
||||
out.key = string.format('key = "%s",', m.key)
|
||||
table.insert(outs_lua, out)
|
||||
end
|
||||
|
||||
--lua
|
||||
out.action = string.format('action = "%s"', m.action)
|
||||
max_key_lua = math.max(#out.key, max_key_lua)
|
||||
end
|
||||
|
||||
-- help
|
||||
local file = io.open("/tmp/DEFAULT_MAPPINGS.help", "w")
|
||||
io.output(file)
|
||||
io.write "\n"
|
||||
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key_help, max_key_help, max_action_help, max_action_help)
|
||||
for _, m in pairs(outs_help) do
|
||||
if m.action == "" then
|
||||
io.write(string.format("%s\n", m.key))
|
||||
else
|
||||
io.write(string.format(fmt, m.key, m.action, m.desc))
|
||||
end
|
||||
end
|
||||
io.write "\n"
|
||||
io.close(file)
|
||||
|
||||
-- lua
|
||||
file = io.open("/tmp/DEFAULT_MAPPINGS.lua", "w")
|
||||
io.output(file)
|
||||
fmt = string.format(" { %%-%d.%ds %%s }\n", max_key_lua, max_key_lua)
|
||||
for _, m in pairs(outs_lua) do
|
||||
io.write(string.format(fmt, m.key, m.action))
|
||||
end
|
||||
io.close(file)
|
||||
|
||||
-- md
|
||||
file = io.open("/tmp/DEFAULT_MAPPINGS.md", "w")
|
||||
io.output(file)
|
||||
io.write "| Default Keys | Action | Description |\n"
|
||||
io.write "| - | - | - |\n"
|
||||
for _, m in pairs(M.mappings) do
|
||||
local keys = ""
|
||||
if type(m.key) == "table" then
|
||||
local first = true
|
||||
for _, sub_key in pairs(m.key) do
|
||||
keys = keys .. (first and "" or " <br /> ") .. sub_key:gsub("<", "\\<")
|
||||
first = false
|
||||
end
|
||||
else
|
||||
keys = m.key:gsub("<", "\\<")
|
||||
end
|
||||
io.write(string.format("| %s | %s | %s |\n", keys, m.action, m.desc:gsub("|", "`")))
|
||||
end
|
||||
io.close(file)
|
||||
44
scripts/update-default-opts.sh
Executable file
44
scripts/update-default-opts.sh
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
|
||||
# run after changing nvim-tree.lua DEFAULT_OPTS or nvim-tree/actions/init.lua M.mappings
|
||||
# scrapes and updates README.md, nvim-tree-lua.txt
|
||||
# run from repositry root: scripts/update-default-opts.sh
|
||||
|
||||
|
||||
begin="BEGIN_DEFAULT_OPTS"
|
||||
end="END_DEFAULT_OPTS"
|
||||
|
||||
# scrape DEFAULT_OPTS, indented at 2
|
||||
sed -n -e "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree.lua > /tmp/DEFAULT_OPTS.2.lua
|
||||
|
||||
# indent some more
|
||||
sed -e "s/^ / /" /tmp/DEFAULT_OPTS.2.lua > /tmp/DEFAULT_OPTS.6.lua
|
||||
|
||||
# README.md indented at 2
|
||||
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_OPTS.2.lua
|
||||
}; /${end}/p; d }" README.md
|
||||
|
||||
# help, indented at 6
|
||||
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_OPTS.6.lua
|
||||
}; /${end}/p; d }" doc/nvim-tree-lua.txt
|
||||
|
||||
|
||||
begin="BEGIN_DEFAULT_MAPPINGS"
|
||||
end="END_DEFAULT_MAPPINGS"
|
||||
|
||||
# generate various DEFAULT_MAPPINGS
|
||||
sed -n -e "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree/actions/init.lua > /tmp/DEFAULT_MAPPINGS.M.lua
|
||||
lua <(cat /tmp/DEFAULT_MAPPINGS.M.lua scripts/generate_default_mappings.lua)
|
||||
|
||||
# README.md
|
||||
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_MAPPINGS.lua
|
||||
}; /${end}/p; d }" README.md
|
||||
sed -i -e "/BEGIN_DEFAULT_MAPPINGS_TABLE/,/END_DEFAULT_MAPPINGS_TABLE/{ /BEGIN_DEFAULT_MAPPINGS_TABLE/{p; r /tmp/DEFAULT_MAPPINGS.md
|
||||
}; /END_DEFAULT_MAPPINGS_TABLE/p; d }" README.md
|
||||
|
||||
# help
|
||||
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_MAPPINGS.lua
|
||||
}; /${end}/p; d }" doc/nvim-tree-lua.txt
|
||||
sed -i -e "/^DEFAULT MAPPINGS/,/^>$/{ /^DEFAULT MAPPINGS/{p; r /tmp/DEFAULT_MAPPINGS.help
|
||||
}; /^>$/p; d }" doc/nvim-tree-lua.txt
|
||||
|
||||
Reference in New Issue
Block a user