From 526873bef425574974358b7f26975cdd7d7cdd1b Mon Sep 17 00:00:00 2001 From: Alin Mr Date: Fri, 3 May 2024 13:22:51 +0000 Subject: show locking pid on conflict; clearer prompt --- init.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 37504ce..0c47973 100644 --- a/init.lua +++ b/init.lua @@ -31,9 +31,9 @@ end -- get a user confirmation -- return true if user selected yes, false otherwise -local function confirm(path) +local function confirm(path, pid) local choices = 'no\nyes' - local prompt = path .. ' exists. Edit anyway:' + local prompt = path .. ' for PID '..pid .. ' exists. Edit anyway:' local cmd = 'printf %s \'' .. choices .. '\' | vis-menu -b -p \'' .. prompt .. '\'' -- local status, output = vis:pipe(nil, {start = 0, finish = 0}, cmd) @@ -43,7 +43,7 @@ local function confirm(path) vis:redraw() if status == 0 then - return 'yes' == output:sub(1, 3) + return output:find('^edit') ~= nil end return false end @@ -56,9 +56,10 @@ vis.events.subscribe(vis.events.FILE_OPEN, function(file) return end local lfile_path = lockfiles.lock_file_path(get_lock_dir(), file.path) - if lockfiles.create_lock_file(get_lock_dir(), lfile_path) then + local lock_pid = lockfiles.create_lock_file(get_lock_dir(), lfile_path) + if lockfiles.vis_pid == lock_pid then created_locks[file.path] = lfile_path - elseif not confirm(lfile_path) then + elseif not confirm(lfile_path, lock_pid) then vis:exit(1) end end) -- cgit v1.2.3