diff --git a/plugin/wakatime.vim b/plugin/wakatime.vim index 95bc118..859559d 100644 --- a/plugin/wakatime.vim +++ b/plugin/wakatime.vim @@ -90,14 +90,6 @@ let s:VERSION = '9.0.1' " Buffering heartbeats disabled in Windows, unless have async support let s:buffering_heartbeats_enabled = s:has_async || s:nvim_async || !s:IsWindows() - " Fix for MSYS2 https://github.com/wakatime/vim-wakatime/issues/122 - if s:IsWindows() - let result = matchlist(s:plugin_root_folder, '^/\([a-zA-Z]\)/.\+/\([a-zA-Z]\):/.\+') - if len(result) > 1 && toupper(result[1]) == toupper(result[2]) - let s:plugin_root_folder = substitute(s:plugin_root_folder, '^/\([a-zA-Z]\)/.\+/\([a-zA-Z]\):/', '/\2/', '') - endif - endif - " Turn on autoupdate only when using default ~/.wakatime/wakatime-cli let s:autoupdate_cli = s:false @@ -150,17 +142,26 @@ let s:VERSION = '9.0.1' " First try install wakatime-cli in background, then using Vim's Python if !empty(python_bin) let install_script = s:plugin_root_folder . '/scripts/install_cli.py' - let cmd = [python_bin, '-W', 'ignore', install_script, s:home] - if s:IsWindows() && &shell =~ 'cmd' - let job_cmd = split(&shell) + split(&shellcmdflag) + cmd - else - let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)] + if s:IsWindows() && s:Chomp(system(s:JoinArgs([python_bin, '-VV'])) !~ 'MSC') + " MSYS2 + let install_script = '/' . substitute(install_script, ':', '', '') endif + let cmd = [python_bin, '-W', 'ignore', install_script, s:home] if s:has_async + if s:IsWindows() && &shell =~ 'cmd' + let job_cmd = [&shell, &shellcmdflag] + cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let job = job_start(job_cmd, { \ 'stoponexit': '', \ 'callback': {channel, output -> s:AsyncInstallHandler(output)}}) elseif s:nvim_async + if s:IsWindows() + let job_cmd = cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let s:nvim_async_output = [''] let job_opts = { \ 'on_stdout': function('s:NeovimAsyncInstallOutputHandler'), @@ -217,14 +218,19 @@ EOF endif let code = py . " import sys, vim;from os.path import abspath, join;sys.path.insert(0, abspath(join('" . s:plugin_root_folder . "', 'scripts')));from install_cli import main;main(home='" . s:home . "');" let cmd = [v:progname, '-u', 'NONE', '-c', code, '+qall'] - if s:IsWindows() && &shell =~ 'cmd' - let job_cmd = split(&shell) + split(&shellcmdflag) + cmd - else - let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)] - endif if s:has_async + if s:IsWindows() && &shell =~ 'cmd' + let job_cmd = [&shell, &shellcmdflag] + cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let job = job_start(job_cmd, {'stoponexit': ''}) elseif s:nvim_async + if s:IsWindows() + let job_cmd = cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let job_opts = {} if !s:IsWindows() let job_opts['detach'] = 1 @@ -500,12 +506,12 @@ EOF set shell=sh shellredir=>%s\ 2>&1 endif - if s:IsWindows() && &shell =~ 'cmd' - let job_cmd = [&shell, &shellcmdflag] + cmd - else - let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)] - endif if s:has_async + if s:IsWindows() && &shell =~ 'cmd' + let job_cmd = [&shell, &shellcmdflag] + cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let job = job_start(job_cmd, { \ 'stoponexit': '', \ 'callback': {channel, output -> s:AsyncHandler(output, cmd)}}) @@ -514,6 +520,11 @@ EOF call ch_sendraw(channel, extra_heartbeats . "\n") endif elseif s:nvim_async + if s:IsWindows() + let job_cmd = cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let s:nvim_async_output = [''] let job_opts = { \ 'on_stdout': function('s:NeovimAsyncOutputHandler'), @@ -720,17 +731,22 @@ EOF function! g:WakaTimeToday() let cmd = [s:wakatime_cli, '--today'] - if s:IsWindows() && &shell =~ 'cmd' - let job_cmd = [&shell, &shellcmdflag] + cmd - else - let job_cmd = split(&shell) + split(&shellcmdflag) + [s:JoinArgs(cmd)] - endif if s:has_async + if s:IsWindows() && &shell =~ 'cmd' + let job_cmd = [&shell, &shellcmdflag] + cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let job = job_start(job_cmd, { \ 'stoponexit': '', \ 'callback': {channel, output -> s:AsyncTodayHandler(output, cmd)}}) elseif s:nvim_async + if s:IsWindows() + let job_cmd = cmd + else + let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)] + endif let job_opts = { \ 'on_stdout': function('s:NeovimAsyncTodayOutputHandler'), \ 'on_stderr': function('s:NeovimAsyncTodayOutputHandler'), diff --git a/scripts/install_cli.py b/scripts/install_cli.py index f66c72e..1403508 100644 --- a/scripts/install_cli.py +++ b/scripts/install_cli.py @@ -472,15 +472,21 @@ def download(url, filePath): def createSymlink(): if is_win: link = os.path.join(getResourcesFolder(), 'wakatime-cli.exe') - if os.path.exists(link): + exists = os.path.exists(link) + if exists and not os.path.islink(link): try: os.remove(link) + exists = False except: log(traceback.format_exc()) - try: - shutil.copy2(getCliLocation(), link) - except: - log(traceback.format_exc()) + if not exists: + try: + os.symlink(getCliLocation(), link) + except: + try: + shutil.copy2(getCliLocation(), link) + except: + log(traceback.format_exc()) else: link = os.path.join(getResourcesFolder(), 'wakatime-cli') if not os.path.exists(link):