diff --git a/README.md b/README.md index 5fd876d..816f987 100644 --- a/README.md +++ b/README.md @@ -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, ... }) @@ -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 diff --git a/README.norg b/README.norg index a1a7821..1013f0f 100644 --- a/README.norg +++ b/README.norg @@ -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 @@ -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, ... }) @@ -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. diff --git a/lua/pathlib/base.lua b/lua/pathlib/base.lua index 3fc66c2..1541668 100644 --- a/lua/pathlib/base.lua +++ b/lua/pathlib/base.lua @@ -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 "" will be preceded by a backslash. The backslash will be removed again by the |:!| command. See `:h shellescape` for more details. The character is escaped. +---@param special boolean|nil # If true, special items such as "!", "%", "#" and "" will be preceded by a backslash. The backslash will be removed again by the `:!` command. See `:h shellescape` for more details. The character is escaped. ---@return PathlibString function Path:shell_string(special) local s = table.concat( diff --git a/lua/pathlib/utils/init.lua b/lua/pathlib/utils/init.lua index d01a247..9bcf912 100644 --- a/lua/pathlib/utils/init.lua +++ b/lua/pathlib/utils/init.lua @@ -1,3 +1,5 @@ +local nuv = require("pathlib.utils.nuv") + local M = { tables = require("pathlib.utils.tables"), lists = require("pathlib.utils.lists"), @@ -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 }) diff --git a/lua/pathlib/utils/nuv.lua b/lua/pathlib/utils/nuv.lua index 4c33c62..7f75b8e 100644 --- a/lua/pathlib/utils/nuv.lua +++ b/lua/pathlib/utils/nuv.lua @@ -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({}, {