vis-config
lua scripts to configure vis editor
git clone https://9o.is/git/vis-config.git
commit ce5fa6ba19d7a0f8a1829ec9d7cc79bb5a3da0dd parent 1f841de1422cc46b48487fbf8d33dd8cd8ca9f04 Author: Jul <jul@9o.is> Date: Thu, 26 Feb 2026 01:55:40 +0800 handle tag-search errors (file not found) Diffstat:
| M | lib/search.lua | | | 23 | ++++++++++++++++++++--- |
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/lib/search.lua b/lib/search.lua @@ -25,10 +25,20 @@ local function dirname(path) end end +local function exists(path) + local f = io.open(path, 'r') + if f then + f:close() + return true + else + return false + end +end + local function run(command, onsuccess, fullscreen) vis.ui:showcursor(true) - local file = io.popen(string.format('sh -c "%s"', command:gsub('"', '\\"'))) + local file = io.popen(string.format('sh -c "%s" 2>/dev/null', command:gsub('"', '\\"'))) local out = file:read() local success, msg, status = file:close() @@ -90,10 +100,17 @@ vis:command_register('mru', function(argv, force, win) return run(cmd, win.navigate) end, 'Most recently used files') -vis:command_register('tag-search', function() +vis:command_register('tag-search', function(argv, _, win) + local tagfile = argv[1] or '.tags' + + if not exists(tagfile) then + vis:info(string.format('tag-search: tag file %s not found', tagfile)) + return + end + local command = string.format([[ readtags -t %s -F '(list \$input ":" \$line ": " \$kind " " \$name #t)' -l | - column -td -C right | fzy]], argv[1] or '.tags') + column -td -C right | fzy]], tagfile) return run(command, function(out) out = split(out, ':')