|
1 | 1 | local log = require("nvim-tree.log") |
2 | 2 | local utils = require("nvim-tree.utils") |
| 3 | +local config = require("nvim-tree.config") |
3 | 4 |
|
4 | | -local M = { |
5 | | - use_cygpath = false, |
6 | | -} |
| 5 | +local M = {} |
| 6 | + |
| 7 | +---@type boolean? |
| 8 | +local use_cygpath_cached = nil |
| 9 | + |
| 10 | +---true when cygwin enabled and present |
| 11 | +---@return boolean |
| 12 | +local function use_cygpath() |
| 13 | + if use_cygpath_cached == nil then |
| 14 | + if config.g.git.cygwin_support then |
| 15 | + use_cygpath_cached = vim.fn.executable("cygpath") == 1 |
| 16 | + else |
| 17 | + use_cygpath_cached = false |
| 18 | + end |
| 19 | + end |
| 20 | + return use_cygpath_cached |
| 21 | +end |
7 | 22 |
|
8 | 23 | --- Execute system command |
9 | 24 | ---@param cmd string[] |
10 | 25 | ---@return string stdout |
11 | 26 | ---@return integer exit code |
12 | 27 | local function system(cmd) |
13 | 28 | if vim.fn.has("nvim-0.10") == 1 then |
14 | | - local obj = vim.system(cmd):wait(M.opts.git.timeout) |
| 29 | + local obj = vim.system(cmd):wait(config.g.git.timeout) |
15 | 30 | return obj.stdout or "", obj.code |
16 | 31 | else |
17 | 32 | return vim.fn.system(cmd), vim.v.shell_error |
@@ -50,7 +65,7 @@ function M.get_toplevel(cwd) |
50 | 65 | if vim.fn.has("win32") == 1 then |
51 | 66 | -- msys2 git support |
52 | 67 | -- cygpath calls must in array format to avoid shell compatibility issues |
53 | | - if M.use_cygpath then |
| 68 | + if use_cygpath() then |
54 | 69 | toplevel = vim.fn.system({ "cygpath", "-w", toplevel }) |
55 | 70 | if vim.v.shell_error ~= 0 then |
56 | 71 | return nil, nil |
@@ -195,11 +210,4 @@ function M.git_status_dir(parent_ignored, project, path, path_fallback) |
195 | 210 | return ns |
196 | 211 | end |
197 | 212 |
|
198 | | -function M.setup(opts) |
199 | | - if opts.git.cygwin_support then |
200 | | - M.use_cygpath = vim.fn.executable("cygpath") == 1 |
201 | | - end |
202 | | - M.opts = opts |
203 | | -end |
204 | | - |
205 | 213 | return M |
0 commit comments