Skip to content

Commit 9f00c7b

Browse files
authored
feat(install): support 'reinstall' on Windows (#62)
1 parent 91e89c9 commit 9f00c7b

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,47 @@ And multiple trigger timings (colorschemes don't have end time):
7878

7979
## ✅ Requirement
8080

81-
- Neovim ≥ 0.8.
82-
- [Git](https://git-scm.com/).
81+
- neovim ≥ 0.8.
82+
- [git](https://git-scm.com/).
83+
- [rm](https://man7.org/linux/man-pages/man1/rm.1.html) (optional for `reinstall` command on Windows).
84+
85+
<details>
86+
<summary><i>Click here to see how to install `rm` command on Windows</i></summary>
87+
<br/>
88+
89+
There're many ways to install portable linux shell and builtin commands on Windows, but personally I would recommend below two methods.
90+
91+
### [Git for Windows](https://git-scm.com/download/win)
92+
93+
Install with the below 3 options:
94+
95+
- In **Select Components**, select **Associate .sh files to be run with Bash**.
96+
97+
<img alt="install-windows-git1.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git1.png" width="70%" />
98+
99+
- In **Adjusting your PATH environment**, select **Use Git and optional Unix tools from the Command Prompt**.
100+
101+
<img alt="install-windows-git2.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git2.png" width="70%" />
102+
103+
- In **Configuring the terminal emulator to use with Git Bash**, select **Use Windows's default console window**.
104+
105+
<img alt="install-windows-git3.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git3.png" width="70%" />
106+
107+
After this step, **git.exe** and builtin linux commands(such as **rm.exe**) will be available in `%PATH%`.
108+
109+
### [scoop](https://scoop.sh/)
110+
111+
Run below powershell commands:
112+
113+
```powershell
114+
# scoop
115+
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
116+
irm get.scoop.sh | iex
117+
118+
scoop install coreutils # rm
119+
```
120+
121+
</details>
83122

84123
## 📦 Install
85124

lua/colorbox.lua

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,38 @@ local function _clean()
508508
)
509509
return
510510
end
511-
vim.cmd(string.format([[silent execute "!rm -rf %s"]], full_pack_dir))
512-
logger.info("cleaned directory: %s", shorten_pack_dir)
511+
if vim.fn.executable("rm") > 0 then
512+
local jobid = vim.fn.jobstart({ "rm", "-rf", full_pack_dir }, {
513+
detach = false,
514+
stdout_buffered = true,
515+
stderr_buffered = true,
516+
on_stdout = function(chanid, data, name)
517+
logger.debug(
518+
"clean job(%s) data:%s",
519+
vim.inspect(name),
520+
vim.inspect(data)
521+
)
522+
end,
523+
on_stderr = function(chanid, data, name)
524+
logger.debug(
525+
"clean job(%s) data:%s",
526+
vim.inspect(name),
527+
vim.inspect(data)
528+
)
529+
end,
530+
on_exit = function(jid, exitcode, name)
531+
logger.debug(
532+
"clean job(%s) done:%s",
533+
vim.inspect(name),
534+
vim.inspect(exitcode)
535+
)
536+
end,
537+
})
538+
vim.fn.jobwait({ jobid })
539+
logger.info("cleaned directory: %s", shorten_pack_dir)
540+
else
541+
logger.warn("no 'rm' command found, skip cleaning...")
542+
end
513543
end
514544

515545
--- @param args string?

lua/colorbox/utils.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local is_windows = vim.fn.has("win32") > 0 or vim.fn.has("win64") > 0
12
local int32_max = 2 ^ 31 - 1
23

34
-- Returns the XOR of two binary numbers
@@ -118,6 +119,7 @@ local function readfile(filename, opts)
118119
end
119120

120121
local M = {
122+
is_windows = is_windows,
121123
int32_max = int32_max,
122124
min = min,
123125
math_mod = math_mod,

0 commit comments

Comments
 (0)