e: rework to pass all paths at once

This commit is contained in:
Josh Holtrop 2026-05-13 16:15:33 -04:00
parent 0d443f89d4
commit 4f15356578

41
e
View File

@ -32,36 +32,23 @@ def run_dir
ENV["XDG_RUNTIME_DIR"] || "/tmp" ENV["XDG_RUNTIME_DIR"] || "/tmp"
end end
def launch(socket_path, pretty_name, path)
if File.exist?(socket_path)
# Server running, send it remote command
system("nvim", "--headless", "--server", socket_path, "--remote-tab-silent", path)
else
# Start the server
$started_server = true
system(EDITOR, path, "--", "--listen", socket_path)
end
end
if ARGV.empty? if ARGV.empty?
exec(EDITOR) exec(EDITOR)
else else
ARGV.each_with_index do |path, i| socket_name, pretty_name = find_proj_root(ARGV[0])
socket_name, pretty_name = find_proj_root(path) if socket_name
socket_path = "#{run_dir}/e-#{socket_name}.sock" socket_path = "#{run_dir}/e-#{socket_name}.sock"
if i == 1 if File.exist?(socket_path)
20.times do tabedits = ARGV.map do |path|
sleep(0.01) path = File.expand_path(path).gsub(" ", "\\ ")
break if File.exist?(socket_path) %[:tabe #{path}<CR>]
end end.join
end puts tabedits
launch(socket_path, pretty_name, path) exec("nvim", "--headless", "--server", socket_path, "--remote-send", "<Esc>#{tabedits}:call GuiForeground()<CR><C-l>")
if i == ARGV.length - 1 else
# This is the last argument. If the server was not started for any paths, exec(EDITOR, "--", "--listen", socket_path, "-p", *ARGV)
# then request that the window take focus. end
unless $server_started else
system("nvim", "--headless", "--server", socket_path, "--remote-send", "<Esc>:call GuiForeground()<CR><C-l>") exec(EDITOR, "--", "-p", *ARGV)
end
end
end end
end end