diff --git a/plugin/wakatime.vim b/plugin/wakatime.vim index 601885d..81e7427 100644 --- a/plugin/wakatime.vim +++ b/plugin/wakatime.vim @@ -126,13 +126,13 @@ let s:VERSION = '9.0.1' let path = path . '.exe' endif - " Check for wakatime-cli installed via Homebrew - if !filereadable(path) && filereadable('/usr/local/bin/wakatime-cli') - let s:wakatime_cli = '/usr/local/bin/wakatime-cli' + " Check for wakatime-cli + if !filereadable(path) && executable('wakatime-cli') + let s:wakatime_cli = 'wakatime-cli' - " Check for wakatime binary in /usr/bin - elseif !filereadable(path) && filereadable('/usr/bin/wakatime') - let s:wakatime_cli = '/usr/bin/wakatime' + " Check for wakatime + elseif !filereadable(path) && executable('wakatime') + let s:wakatime_cli = 'wakatime' " Default to ~/.wakatime/wakatime-cli-- else @@ -144,17 +144,17 @@ let s:VERSION = '9.0.1' endfunction function! s:InstallCLI(use_external_python) - if !s:autoupdate_cli && filereadable(s:wakatime_cli) + if !s:autoupdate_cli && executable(s:wakatime_cli) return endif - let python_bin = s:false + let python_bin = '' if a:use_external_python let python_bin = s:GetPythonBinary() endif " First try install wakatime-cli in background, then using Vim's Python - if !empty(python_bin) && python_bin != s:false + 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:has_async @@ -371,36 +371,35 @@ EOF if has('g:wakatime_PythonBinary') let python_bin = g:wakatime_PythonBinary endif - if !empty(python_bin) && !filereadable(python_bin) && !executable(python_bin) + if empty(python_bin) || !filereadable(python_bin) || !executable(python_bin) if executable('python3') let python_bin = 'python3' elseif executable('python') let python_bin = 'python' - endif - endif - if !empty(python_bin) && !filereadable(python_bin) && !executable(python_bin) - let paths = ['python3'] - if s:IsWindows() - let pyver = 39 - while pyver >= 27 - let paths = paths + [printf('/Python%d/pythonw', pyver), printf('/python%d/pythonw', pyver), printf('/Python%d/python', pyver), printf('/python%d/python', pyver)] - let pyver = pyver - 1 - endwhile else - let paths = paths + ['/usr/bin/python3', '/usr/local/bin/python3', '/usr/bin/python3.6', '/usr/local/bin/python3.6', '/usr/bin/python', '/usr/local/bin/python', '/usr/bin/python2', '/usr/local/bin/python2'] - endif - let paths = paths + ['python'] - let index = 0 - let limit = len(paths) - while index < limit - if filereadable(paths[index]) - let python_bin = paths[index] - let index = limit + let paths = ['python3'] + if s:IsWindows() + let pyver = 39 + while pyver >= 27 + let paths = paths + [printf('/Python%d/pythonw', pyver), printf('/python%d/pythonw', pyver), printf('/Python%d/python', pyver), printf('/python%d/python', pyver)] + let pyver = pyver - 1 + endwhile + else + let paths = paths + ['/usr/bin/python3', '/usr/local/bin/python3', '/usr/bin/python3.6', '/usr/local/bin/python3.6', '/usr/bin/python', '/usr/local/bin/python', '/usr/bin/python2', '/usr/local/bin/python2'] endif - let index = index + 1 - endwhile + let paths = paths + ['python'] + let index = 0 + let limit = len(paths) + while index < limit + if filereadable(paths[index]) + let python_bin = paths[index] + let index = limit + endif + let index = index + 1 + endwhile + endif endif - if s:IsWindows() && !empty(python_bin) && (filereadable(printf('%sw', python_bin)) || executable(printf('%sw', python_bin))) + if !empty(python_bin) && s:IsWindows() && (filereadable(printf('%sw', python_bin)) || executable(printf('%sw', python_bin))) let python_bin = printf('%sw', python_bin) endif return python_bin diff --git a/scripts/install_cli.py b/scripts/install_cli.py index 2f4adcf..6de0228 100644 --- a/scripts/install_cli.py +++ b/scripts/install_cli.py @@ -26,13 +26,20 @@ from urllib.error import HTTPError +def getOsName(): + os = platform.system().lower() + if os.startswith('cygwin') or os.startswith('mingw') or os.startswith('msys'): + return 'windows' + return os + + GITHUB_RELEASES_STABLE_URL = 'https://api.github.com/repos/wakatime/wakatime-cli/releases/latest' GITHUB_DOWNLOAD_PREFIX = 'https://github.com/wakatime/wakatime-cli/releases/download' PLUGIN = 'vim' is_py2 = (sys.version_info[0] == 2) is_py3 = (sys.version_info[0] == 3) -is_win = platform.system() == 'Windows' +is_win = getOsName() == 'windows' HOME_FOLDER = None CONFIGS = None @@ -49,10 +56,13 @@ def main(home=None): if not isCliLatest(): downloadCLI() - try: - os.symlink(getCliLocation(), os.path.join(getResourcesFolder(), 'wakatime-cli')) - except: - pass + cli = os.path.join(getResourcesFolder(), 'wakatime-cli') + if not os.path.exists(cli): + try: + os.symlink(getCliLocation(), cli) + except: + # May not have permission on Windows + pass if is_py2: @@ -223,7 +233,7 @@ def getCliLocation(): if not WAKATIME_CLI_LOCATION: binary = 'wakatime-cli-{osname}-{arch}{ext}'.format( - osname=platform.system().lower(), + osname=getOsName(), arch=architecture(), ext='.exe' if is_win else '', ) @@ -337,7 +347,7 @@ def extractVersion(text): def cliDownloadUrl(): - osname = platform.system().lower() + osname = getOsName() arch = architecture() validCombinations = [