From f6919f7f59b8f9f25c7b8c08df4d6f1c2c1850dd Mon Sep 17 00:00:00 2001 From: Alin Mr Date: Fri, 3 May 2024 07:22:57 +0000 Subject: init.lua: simplify 'yes' detection --- init.lua | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index 5c85818..2644eea 100644 --- a/init.lua +++ b/init.lua @@ -34,23 +34,18 @@ end local function confirm(path) local choices = 'no\nyes' local prompt = path .. ' exists. Edit anyway:' - local cmd = 'printf "' .. choices .. '" | vis-menu -b -p \'' .. prompt .. '\'' + local cmd = 'printf %s \'' .. choices .. '\' | vis-menu -b -p \'' .. prompt .. '\'' - local choice = nil -- local status, output = vis:pipe(nil, {start = 0, finish = 0}, cmd) local menu = assert(io.popen(cmd)) local output = menu:read('*a') local _, _, status = menu:close() + vis:redraw() + if status == 0 then - -- trim newline from selection - if output:sub(-1) == '\n' then - choice = output:sub(1, -2) - else - choice = output - end + return 'yes' == output:sub(1, 3) end - vis:redraw() - return choice == 'yes' + return false end local created_locks = {} -- cgit v1.2.3