Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(install): support 'reinstall' on Windows #62

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
)
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 }, {

Check warning on line 512 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L511-L512

Added lines #L511 - L512 were not covered by tests
detach = false,
stdout_buffered = true,
stderr_buffered = true,
on_stdout = function(chanid, data, name)
logger.debug(

Check warning on line 517 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L517

Added line #L517 was not covered by tests
"clean job(%s) data:%s",
vim.inspect(name),
vim.inspect(data)

Check warning on line 520 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L519-L520

Added lines #L519 - L520 were not covered by tests
)
end,
on_stderr = function(chanid, data, name)
logger.debug(

Check warning on line 524 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L524

Added line #L524 was not covered by tests
"clean job(%s) data:%s",
vim.inspect(name),
vim.inspect(data)

Check warning on line 527 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L526-L527

Added lines #L526 - L527 were not covered by tests
)
end,
on_exit = function(jid, exitcode, name)
logger.debug(

Check warning on line 531 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L531

Added line #L531 was not covered by tests
"clean job(%s) done:%s",
vim.inspect(name),
vim.inspect(exitcode)

Check warning on line 534 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L533-L534

Added lines #L533 - L534 were not covered by tests
)
end,
})
vim.fn.jobwait({ jobid })
logger.info("cleaned directory: %s", shorten_pack_dir)

Check warning on line 539 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L538-L539

Added lines #L538 - L539 were not covered by tests
else
logger.warn("no 'rm' command found, skip cleaning...")

Check warning on line 541 in lua/colorbox.lua

View check run for this annotation

Codecov / codecov/patch

lua/colorbox.lua#L541

Added line #L541 was not covered by tests
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
Loading