Update e to use nvim
This commit is contained in:
parent
eb9ba299aa
commit
0b7ebab8c3
74
e
74
e
@ -1,39 +1,67 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
# Use HighContrast GTK2 theme for gvim.
|
require "open3"
|
||||||
ENV["GTK2_RC_FILES"] = "/usr/share/themes/HighContrast/gtk-2.0/gtkrc"
|
|
||||||
|
|
||||||
def get_server_name(path)
|
SEARCH = %w[.git project.vim]
|
||||||
if path
|
EDITOR = "nvim-qt"
|
||||||
path = File.expand_path(path)
|
|
||||||
while path != "/"
|
def find_proj_root(path)
|
||||||
dirname = File.dirname(path)
|
path = File.expand_path(path)
|
||||||
if File.exist?(File.join(dirname, "project.vim"))
|
loop do
|
||||||
if dirname =~ %r{([^/]+)/([^/]+)/*$}
|
dirname = File.dirname(path)
|
||||||
sn = "#{$2}(#{$1})"
|
if SEARCH.any? {|s| File.exist?(File.join(dirname, s))}
|
||||||
else
|
if dirname =~ %r{([^/]+)/([^/]+)/*$}
|
||||||
sn = File.basename(dirname)
|
pretty_name = "#{$2}(#{$1})"
|
||||||
end
|
else
|
||||||
return sn
|
pretty_name = File.basename(dirname)
|
||||||
end
|
end
|
||||||
path = dirname
|
stdout, stderr, status = Open3.capture3("xxh32sum", stdin_data: dirname)
|
||||||
|
socket_name = stdout.sub(/\s.*/m, "")
|
||||||
|
return [socket_name, pretty_name]
|
||||||
|
end
|
||||||
|
path = dirname
|
||||||
|
if path == "/"
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return "GVIM"
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def server_running?(server_name)
|
def run_dir
|
||||||
`gvim --serverlist`.lines.map(&:chomp).include?(server_name.upcase)
|
ENV["XDG_RUNTIME_DIR"] || "/tmp"
|
||||||
|
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
|
end
|
||||||
|
|
||||||
if ARGV.empty?
|
if ARGV.empty?
|
||||||
server_name = get_server_name('local_file')
|
exec(EDITOR)
|
||||||
exec("/usr/bin/gvim", "--servername", server_name, err: "/dev/null")
|
|
||||||
else
|
else
|
||||||
ARGV.each_with_index do |path, i|
|
ARGV.each_with_index do |path, i|
|
||||||
server_name = get_server_name(path)
|
socket_name, pretty_name = find_proj_root(path)
|
||||||
sleep(0.2) if i > 0
|
socket_path = "#{run_dir}/e-#{socket_name}.sock"
|
||||||
system("/usr/bin/gvim", "--servername", server_name, "--remote-tab-silent", path, err: "/dev/null")
|
if i == 1
|
||||||
|
20.times do
|
||||||
|
sleep(0.01)
|
||||||
|
break if File.exist?(socket_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
launch(socket_path, pretty_name, path)
|
||||||
|
if i == ARGV.length - 1
|
||||||
|
# This is the last argument. If the server was not started for any paths,
|
||||||
|
# then request that the window take focus.
|
||||||
|
unless $server_started
|
||||||
|
system("nvim", "--headless", "--server", socket_path, "--remote-send", "<Esc>:call GuiForeground()<CR><C-l>")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user