|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +# Wrapper around Nvim make targets: |
| 4 | +# |
| 5 | +# make doc - gen_vimdoc.lua |
| 6 | +# Generates doc/nvim-tree-lua.txt |
| 7 | +# Uses nvim-tree sources defined in scripts/vimdoc_config.lua |
| 8 | +# Shims above into src/gen/gen_vimdoc.lua, replacing Nvim's config. |
| 9 | +# |
| 10 | +# make lintdoc - lintdoc.lua |
| 11 | +# Validates doc/nvim-tree-lua.txt |
| 12 | +# Desired: |
| 13 | +# - tags valid |
| 14 | +# - links valid |
| 15 | +# Also: |
| 16 | +# - brand spelling, notably Nvim and Lua |
| 17 | +# |
| 18 | +# There are some hardcoded expectations which we work around as commented. |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +if [ $# -ne 1 ] || [ "${1}" != "doc" ] && [ "${1}" != "lintdoc" ]; then |
| 23 | + echo "usage: ${0} <doc|lintdoc>" 1>&2 |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +DIR_NVIM_SRC_DEF="/tmp/src/neovim-stable" |
| 28 | + |
| 29 | +if [ ! -d "lua/nvim-tree" ]; then |
| 30 | + echo "Must be run from nvim-tree root" 1>&2 |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +if [ -z "${DIR_NVIM_SRC}" ] && [ -d "${DIR_NVIM_SRC_DEF}" ]; then |
| 35 | + export DIR_NVIM_SRC="${DIR_NVIM_SRC_DEF}" |
| 36 | +fi |
| 37 | + |
| 38 | +if [ ! -d "${DIR_NVIM_SRC}" ]; then |
| 39 | + cat << EOM |
| 40 | +
|
| 41 | +Nvim source v0.11+ is required to run ${0} |
| 42 | +
|
| 43 | +Unavailable: ${DIR_NVIM_SRC_DEF} or \$DIR_NVIM_SRC=${DIR_NVIM_SRC} |
| 44 | +
|
| 45 | +Please: |
| 46 | + mkdir -p ${DIR_NVIM_SRC_DEF} |
| 47 | + curl -L 'https://github.com/neovim/neovim/archive/refs/tags/stable.tar.gz' | tar zx --directory $(dirname "${DIR_NVIM_SRC_DEF}") |
| 48 | + or use your own e.g. |
| 49 | + export DIR_NVIM_SRC="\${HOME}/src/neovim" |
| 50 | +
|
| 51 | +EOM |
| 52 | +exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +function cleanup() { |
| 56 | + # remove source link |
| 57 | + rm -fv "${DIR_NVIM_SRC}/runtime/lua/nvim_tree" |
| 58 | + |
| 59 | + # remove our config |
| 60 | + rm -fv "${DIR_NVIM_SRC}/src/gen/gen_vimdoc_nvim_tree.lua" |
| 61 | + |
| 62 | + # remove generated help |
| 63 | + rm -fv "${DIR_NVIM_SRC}/runtime/doc/nvim-tree-lua.txt" |
| 64 | + |
| 65 | + # revert generator if present |
| 66 | + if [ -f "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua.org" ]; then |
| 67 | + mv -v "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua.org" "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua" |
| 68 | + fi |
| 69 | +} |
| 70 | + |
| 71 | +# clean up any previous failed runs |
| 72 | +cleanup |
| 73 | + |
| 74 | +# runtime/doc is hardcoded, copy the help in |
| 75 | +cp -v "doc/nvim-tree-lua.txt" "${DIR_NVIM_SRC}/runtime/doc" |
| 76 | + |
| 77 | +# setup doc generation |
| 78 | +if [ "${1}" = "doc" ]; then |
| 79 | + # runtime/lua is available, link our sources in there |
| 80 | + # gen_vimdoc.lua doesn't like dashes in lua module names |
| 81 | + # -> use nvim_tree instead of nvim-tree |
| 82 | + ln -sv "${PWD}/lua/nvim-tree" "${DIR_NVIM_SRC}/runtime/lua/nvim_tree" |
| 83 | + |
| 84 | + # modify gen_vimdoc.lua to use our config, backing up original |
| 85 | + cp "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua" "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua.org" |
| 86 | + sed -i -E 's/spairs\(config\)/spairs\(require("gen.vimdoc_config")\)/g' "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua" |
| 87 | + |
| 88 | + # copy our config |
| 89 | + cp -v "scripts/vimdoc_config.lua" "${DIR_NVIM_SRC}/src/gen" |
| 90 | +fi |
| 91 | + |
| 92 | +# run from within Nvim source |
| 93 | +cd "${DIR_NVIM_SRC}" |
| 94 | +make "${1}" |
| 95 | +cd - |
| 96 | + |
| 97 | +# copy the generated help out |
| 98 | +cp -v "${DIR_NVIM_SRC}/runtime/doc/nvim-tree-lua.txt" "doc" |
| 99 | + |
| 100 | +# cleanup as everything succeeded |
| 101 | +cleanup |
0 commit comments