From d4348b1e5260b3c00c8e1f85a8db8aa0f483a675 Mon Sep 17 00:00:00 2001 From: Diogo Felix Date: Fri, 18 Jan 2019 22:35:35 -0200 Subject: [PATCH] use neovim if command is present otherwise use vim --- lib/vimgolf/lib/vimgolf/cli.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/vimgolf/lib/vimgolf/cli.rb b/lib/vimgolf/lib/vimgolf/cli.rb index 14bcb0c..5771163 100644 --- a/lib/vimgolf/lib/vimgolf/cli.rb +++ b/lib/vimgolf/lib/vimgolf/cli.rb @@ -1,9 +1,20 @@ module VimGolf + def self.which(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each { |ext| + exe = File.join(path, "#{cmd}#{ext}") + return exe if File.executable?(exe) && !File.directory?(exe) + } + end + return nil + end + EXECUTABLE = (if not self.which('nvim').nil? then 'nvim' else 'vim' end) GOLFDEBUG = ENV['GOLFDEBUG'].to_sym rescue false GOLFHOST = ENV['GOLFHOST'] || "http://www.vimgolf.com" - GOLFSHOWDIFF = ENV['GOLFSHOWDIFF'] || 'vim -d -n' - GOLFVIM = ENV['GOLFVIM'] || 'vim' + GOLFSHOWDIFF = ENV['GOLFSHOWDIFF'] || "#{EXECUTABLE} -d -n" + GOLFVIM = ENV['GOLFVIM'] || "#{EXECUTABLE}" PROXY = ENV['http_proxy'] || '' class Error