Skip to content

Commit

Permalink
feat(install): support 'reinstall' on Windows (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 committed Nov 24, 2023
1 parent 91e89c9 commit 9f00c7b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,47 @@ And multiple trigger timings (colorschemes don't have end time):

## ✅ Requirement

- Neovim ≥ 0.8.
- [Git](https://git-scm.com/).
- neovim ≥ 0.8.
- [git](https://git-scm.com/).
- [rm](https://man7.org/linux/man-pages/man1/rm.1.html) (optional for `reinstall` command on Windows).

<details>
<summary><i>Click here to see how to install `rm` command on Windows</i></summary>
<br/>

There're many ways to install portable linux shell and builtin commands on Windows, but personally I would recommend below two methods.

### [Git for Windows](https://git-scm.com/download/win)

Install with the below 3 options:

- In **Select Components**, select **Associate .sh files to be run with Bash**.

<img alt="install-windows-git1.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git1.png" width="70%" />

- In **Adjusting your PATH environment**, select **Use Git and optional Unix tools from the Command Prompt**.

<img alt="install-windows-git2.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git2.png" width="70%" />

- In **Configuring the terminal emulator to use with Git Bash**, select **Use Windows's default console window**.

<img alt="install-windows-git3.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git3.png" width="70%" />

After this step, **git.exe** and builtin linux commands(such as **rm.exe**) will be available in `%PATH%`.

### [scoop](https://scoop.sh/)

Run below powershell commands:

```powershell
# scoop
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex
scoop install coreutils # rm
```

</details>

## 📦 Install

Expand Down
34 changes: 32 additions & 2 deletions lua/colorbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,38 @@ local function _clean()
)
return
end
vim.cmd(string.format([[silent execute "!rm -rf %s"]], full_pack_dir))
logger.info("cleaned directory: %s", shorten_pack_dir)
if vim.fn.executable("rm") > 0 then
local jobid = vim.fn.jobstart({ "rm", "-rf", full_pack_dir }, {
detach = false,
stdout_buffered = true,
stderr_buffered = true,
on_stdout = function(chanid, data, name)
logger.debug(
"clean job(%s) data:%s",
vim.inspect(name),
vim.inspect(data)
)
end,
on_stderr = function(chanid, data, name)
logger.debug(
"clean job(%s) data:%s",
vim.inspect(name),
vim.inspect(data)
)
end,
on_exit = function(jid, exitcode, name)
logger.debug(
"clean job(%s) done:%s",
vim.inspect(name),
vim.inspect(exitcode)
)
end,
})
vim.fn.jobwait({ jobid })
logger.info("cleaned directory: %s", shorten_pack_dir)
else
logger.warn("no 'rm' command found, skip cleaning...")
end
end

--- @param args string?
Expand Down
2 changes: 2 additions & 0 deletions lua/colorbox/utils.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local is_windows = vim.fn.has("win32") > 0 or vim.fn.has("win64") > 0
local int32_max = 2 ^ 31 - 1

-- Returns the XOR of two binary numbers
Expand Down Expand Up @@ -118,6 +119,7 @@ local function readfile(filename, opts)
end

local M = {
is_windows = is_windows,
int32_max = int32_max,
min = min,
math_mod = math_mod,
Expand Down

0 comments on commit 9f00c7b

Please sign in to comment.