@@ -6,37 +6,83 @@ function M.check()
66 local ok = health .ok or health .report_ok
77 local warn = health .warn or health .report_warn
88 local error = health .error or health .report_error
9+ local info = health .info or health .report_info
910
1011 start (" browsher.nvim" )
1112
13+ local version = require (" browsher.version" )
14+ info (" {browsher.nvim} version `" .. version .. " `" )
15+
1216 if vim .fn .executable (" git" ) ~= 1 then
13- error (" Git is not installed or not in PATH. " )
17+ error (" {git} is not installed or not in PATH" )
1418 else
15- ok (" Git is installed." )
19+ local git_version = vim .fn .system (" git --version" ):match (" git version ([%d%.]+)" )
20+ ok (" {git} version `" .. (git_version or " unknown" ) .. " `" )
21+ end
22+
23+ local git_root = vim .fn .systemlist (" git rev-parse --show-toplevel 2>/dev/null" )[1 ]
24+ if vim .v .shell_error ~= 0 or not git_root then
25+ info (" not inside a Git repository" )
26+ else
27+ ok (" inside Git repository `" .. git_root .. " `" )
28+
29+ local remotes = vim .fn .systemlist (" git remote" )
30+ if # remotes == 0 then
31+ warn (" no remotes configured in this repository" )
32+ else
33+ ok (" remote(s) available: `" .. table.concat (remotes , " `, `" ) .. " `" )
34+
35+ local config = require (" browsher.config" )
36+ local url_builder = require (" browsher.url" )
37+ local default_remote = config .options .default_remote or remotes [1 ]
38+ local remote_url = vim .fn .systemlist (" git config --get remote." .. default_remote .. " .url" )[1 ]
39+
40+ if remote_url then
41+ local sanitized = url_builder .sanitize_remote_url (remote_url )
42+ local provider_found = false
43+ for provider , _ in pairs (config .options .providers ) do
44+ if sanitized :match (provider ) then
45+ ok (" provider matched: {" .. provider .. " }" )
46+ provider_found = true
47+ break
48+ end
49+ end
50+ if not provider_found then
51+ warn (" no provider configured for `" .. sanitized .. " `" )
52+ info (" add a custom provider in your config for this remote" )
53+ end
54+ end
55+ end
1656 end
1757
1858 local open_cmd = require (" browsher.config" ).options .open_cmd
1959 if open_cmd then
2060 local cmd = type (open_cmd ) == " string" and open_cmd or open_cmd [1 ]
21- if vim .fn .executable (cmd ) ~= 1 then
22- error (string.format (" Configured open_cmd '%s' is not executable." , cmd ))
61+ if string.len (cmd ) == 1 then
62+ ok (" configured to copy URL to `" .. cmd .. " ` register" )
63+ elseif vim .fn .executable (cmd ) ~= 1 then
64+ error (" {" .. cmd .. " } is not executable" )
2365 else
24- ok (string.format ( " Configured open_cmd '%s' is executable. " , cmd ) )
66+ ok (" { " .. cmd .. " } is executable" )
2567 end
2668 else
27- local has_open_cmd = false
28- if vim .fn .has (" unix" ) == 1 and vim .fn .executable (" xdg-open" ) == 1 then
29- ok (" xdg-open is available." )
30- has_open_cmd = true
31- elseif vim .fn .has (" macunix" ) == 1 and vim .fn .executable (" open" ) == 1 then
32- ok (" 'open' command is available." )
33- has_open_cmd = true
34- elseif vim .fn .has (" win32" ) == 1 then
35- ok (" Windows detected. 'explorer.exe' will be used." )
36- has_open_cmd = true
37- end
38- if not has_open_cmd then
39- warn (" No suitable command found to open URLs. Set 'open_cmd' in configuration." )
69+ local os_name = vim .loop .os_uname ().sysname
70+ if os_name == " Linux" then
71+ if vim .fn .executable (" xdg-open" ) == 1 then
72+ ok (" {xdg-open} is available" )
73+ else
74+ warn (" {xdg-open} is not available, set `open_cmd` in configuration" )
75+ end
76+ elseif os_name == " Darwin" then
77+ if vim .fn .executable (" open" ) == 1 then
78+ ok (" {open} is available" )
79+ else
80+ warn (" {open} is not available, set `open_cmd` in configuration" )
81+ end
82+ elseif os_name == " Windows_NT" then
83+ ok (" Windows detected, {explorer.exe} will be used" )
84+ else
85+ warn (" unknown OS, set `open_cmd` in configuration" )
4086 end
4187 end
4288end
0 commit comments