Skip to content
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
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ print(foo:parent()) -- "/home/user/Documents"

``` lua
local git_root = Path("/path/to/git/workdir")
-- assert(git_root:child(".git"):exists(), string.format("%s is not a git repo.", git_root))
assert(git_root:child(".git"):exists(), string.format("%s is not a git repo.", git_root))

require("pathlib.git").fill_git_state({ file_a, file_b, ... })

Expand Down Expand Up @@ -185,8 +185,18 @@ end)
# TODO

- [ ] API documentation.
- [ ] Git operation integration.
- [x] PathlibPath
- [x] PathlibPosixPath
- [x] PathlibWindowsPath
- [ ] Git
- [x] Git operation integration.
- [ ] Git test suite.
- [ ] List out every possible git state: ignored, staged etc.
- [ ] Create file for each state.
- [ ] Add docs for each state: `man git-diff -> RAW OUTPUT FORMAT`
- [ ] Windows implementation, test environment.
- [ ] Create a CI/CD action to run on windows.
- [ ] Prepare windows specific test suite.

# Contributions

Expand Down
18 changes: 14 additions & 4 deletions README.norg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description:
authors: takuto
categories:
created: 2023-11-14
updated: 2024-02-18T12:33:58+0900
updated: 2024-02-19T08:41:11+0900
version: 1.1.1
@end

Expand Down Expand Up @@ -58,7 +58,7 @@ version: 1.1.1
** 📋 Git Integration
@code lua
local git_root = Path("/path/to/git/workdir")
-- assert(git_root:child(".git"):exists(), string.format("%s is not a git repo.", git_root))
assert(git_root:child(".git"):exists(), string.format("%s is not a git repo.", git_root))

require("pathlib.git").fill_git_state({ file_a, file_b, ... })

Expand Down Expand Up @@ -194,9 +194,19 @@ version: 1.1.1
@end

* TODO
- ( ) API documentation.
- (-) Git operation integration.
- (-) API documentation.
-- (x) PathlibPath
-- (x) PathlibPosixPath
-- (x) PathlibWindowsPath
-- ( ) Git
- (x) Git operation integration.
- ( ) Git test suite.
-- ( ) List out every possible git state: ignored, staged etc.
-- ( ) Create file for each state.
-- ( ) Add docs for each state: `man git-diff -> RAW OUTPUT FORMAT`
- ( ) Windows implementation, test environment.
-- ( ) Create a CI/CD action to run on windows.
-- ( ) Prepare windows specific test suite.

* Contributions
I am not thinking of merging any PRs yet but feel free to give me your opinions with an issue.
Expand Down
2 changes: 1 addition & 1 deletion lua/pathlib/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ end
---
---If result is passed to the `:!` command, set `special` to true.
---
---@param special boolean|nil # If true, special items such as "!", "%", "#" and "<cword>" will be preceded by a backslash. The backslash will be removed again by the |:!| command. See `:h shellescape` for more details. The <NL> character is escaped.
---@param special boolean|nil # If true, special items such as "!", "%", "#" and "<cword>" will be preceded by a backslash. The backslash will be removed again by the `:!` command. See `:h shellescape` for more details. The <NL> character is escaped.
---@return PathlibString
function Path:shell_string(special)
local s = table.concat(
Expand Down
5 changes: 5 additions & 0 deletions lua/pathlib/utils/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local nuv = require("pathlib.utils.nuv")

local M = {
tables = require("pathlib.utils.tables"),
lists = require("pathlib.utils.lists"),
Expand All @@ -14,6 +16,9 @@ end
---@return boolean success
---@return string[] result_lines # Each line of the output from the command.
function M.execute_command(cmd, input)
if nuv.check_nio_install() and nuv.current_task() then
return nuv.execute_command(cmd, input)
end
local result = vim.system(cmd, { stdin = input }):wait()
if result.code == 0 then
return true, vim.split(result.stdout or "", "\n", { plain = true, trimempty = false })
Expand Down
20 changes: 20 additions & 0 deletions lua/pathlib/utils/nuv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ function M.current_task()
end
end

function M.execute_command(cmd, input)
local process, err_msg = M.nio.process.run({
cmd = cmd[1],
args = { unpack(cmd, 2) },
})
if not process then
return false, { err_msg }
end
for i, value in ipairs(input or {}) do
local err = process.stdin.write(value .. "\n")
assert(not err, ([[ERROR cmd: '%s', input(%s): '%s', error: %s]]):format(table.concat(cmd, " "), i, value, err))
end
process.stdin.close()
if process.result() == 0 then
return true, vim.split(process.stdout.read() or "", "\n", { plain = true, trimempty = false })
else
return false, {}
end
end

---@param self PathlibPath
function M.generate_nuv(self)
return setmetatable({}, {
Expand Down