From 62122b10fec5c947fe76f897bbab8d6c7d950ef1 Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Vargas Date: Thu, 19 Nov 2020 14:36:44 -0500 Subject: [PATCH 1/4] Minor refactoring - Refactor rmdir() to make the nop-case more obvious - Remove local variable `dir` from map_pkgs - Remove redundant error handling from paq() --- lua/paq-nvim.lua | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lua/paq-nvim.lua b/lua/paq-nvim.lua index ec3c766..4e5824a 100644 --- a/lua/paq-nvim.lua +++ b/lua/paq-nvim.lua @@ -2,7 +2,7 @@ local loop = vim.loop -- Constants local PATH = vim.fn.stdpath('data') .. '/site/pack/paqs/' local GITHUB = 'https://github.com/' -local REPO_RE = '^[%w-]+/([%w-_.]+)$' --is this regex correct? +local REPO_RE = '^[%w-]+/([%w-_.]+)$' -- Table of 'name':{options} pairs local packages = {} @@ -51,40 +51,38 @@ local function update_pkg(name, dir) end local function map_pkgs(fn) - local dir for name, args in pairs(packages) do - dir = get_dir(name, args.opt) - fn(name, dir, args) + fn(name, get_dir(name, args.opt), args) end end -function rmdir(dir, ispkgdir) - local name, child - local ok = true -- Some calls to this function might be NOP +local function rmdir(dir, ispkgdir) + local name, t, child, ok local handle = loop.fs_scandir(dir) while handle do name, t = loop.fs_scandir_next(handle) if not name then break end + child = dir .. '/' .. name if ispkgdir then --check which packages are listed - if not packages[name] then --package isn't listed + if packages[name] then --do nothing + ok = true + else --package isn't listed, remove it ok = rmdir(child) print_res('uninstall', name, ok) end else --it's an arbitrary directory or file ok = (t == 'directory') and rmdir(child) or loop.fs_unlink(child) end + if not ok then return end end return ispkgdir or loop.fs_rmdir(dir) -- Don't delete start or opt end local function paq(args) - local t = type(args) - if t == 'string' then + if type(args) == 'string' then args = {args} - elseif t ~= 'table' then - return end local reponame = args[1]:match(REPO_RE) From 8f901b7b128e4d7cd907ebe0aab8eb38598b281c Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Vargas Date: Thu, 19 Nov 2020 23:40:16 -0500 Subject: [PATCH 2/4] Refactor path/dir handling Execute all processes from within the modified directory. This will make post-install hooks easier to add (see issue #1). Remove aux functions `get_dir` and `is_pkg_dir`. They're called for every package, in the same place, and only once; might as well inline them. --- lua/paq-nvim.lua | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/lua/paq-nvim.lua b/lua/paq-nvim.lua index 4e5824a..f38cc34 100644 --- a/lua/paq-nvim.lua +++ b/lua/paq-nvim.lua @@ -7,24 +7,16 @@ local REPO_RE = '^[%w-]+/([%w-_.]+)$' -- Table of 'name':{options} pairs local packages = {} -local function get_dir(name, opt) - return PATH .. (opt and 'opt/' or 'start/') .. name -end - -local function is_pkg_dir(dir) - return vim.fn.isdirectory(dir) ~= 0 -end - local function print_res(action, args, ok) local res = ok and 'Paq: ' or 'Paq: Failed to ' print(res .. action .. ' ' .. args) end -local function call_git(action, name, ...) +local function call_git(name, dir, action, ...) local args = {...} local handle handle = loop.spawn('git', - {args=args}, + {args=args, cwd=dir}, vim.schedule_wrap( function(code, signal) print_res(action, name, code == 0) @@ -34,25 +26,29 @@ local function call_git(action, name, ...) ) end -local function install_pkg(name, dir, args) - if not is_pkg_dir(dir) then +local function install_pkg(name, dir, isdir, args) + if not isdir then + loop.fs_mkdir(dir, loop.fs_stat(PATH).mode) if args.branch then - call_git('install', name, 'clone', args.url, '-b', args.branch, '--single-branch', dir) + call_git(name, dir, 'install', 'clone', args.url, '-b', args.branch, '--single-branch', '.') else - call_git('install', name, 'clone', args.url, dir) + call_git(name, dir, 'install', 'clone', args.url, '.') end end end -local function update_pkg(name, dir) - if is_pkg_dir(dir) then - call_git('update', name, '-C', dir, 'pull') +local function update_pkg(name, dir, isdir) + if isdir then + call_git(name, dir, 'update', 'pull') end end local function map_pkgs(fn) + local dir, isdir for name, args in pairs(packages) do - fn(name, get_dir(name, args.opt), args) + dir = PATH .. (opt and 'opt/' or 'start/') .. name + isdir = vim.fn.isdirectory(dir) ~= 0 + fn(name, dir, isdir, args) end end @@ -62,7 +58,6 @@ local function rmdir(dir, ispkgdir) while handle do name, t = loop.fs_scandir_next(handle) if not name then break end - child = dir .. '/' .. name if ispkgdir then --check which packages are listed if packages[name] then --do nothing @@ -74,7 +69,6 @@ local function rmdir(dir, ispkgdir) else --it's an arbitrary directory or file ok = (t == 'directory') and rmdir(child) or loop.fs_unlink(child) end - if not ok then return end end return ispkgdir or loop.fs_rmdir(dir) -- Don't delete start or opt From d8c82b2b40d3b6eac4e02bb0de5f794de2073c39 Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Vargas Date: Fri, 20 Nov 2020 12:08:42 -0500 Subject: [PATCH 3/4] Change vim.loop alias --- lua/paq-nvim.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lua/paq-nvim.lua b/lua/paq-nvim.lua index f38cc34..9304cad 100644 --- a/lua/paq-nvim.lua +++ b/lua/paq-nvim.lua @@ -1,11 +1,10 @@ -local loop = vim.loop -- Constants -local PATH = vim.fn.stdpath('data') .. '/site/pack/paqs/' -local GITHUB = 'https://github.com/' +local PATH = vim.fn.stdpath('data') .. '/site/pack/paqs/' +local GITHUB = 'https://github.com/' local REPO_RE = '^[%w-]+/([%w-_.]+)$' --- Table of 'name':{options} pairs -local packages = {} +local uv = vim.loop -- Alias for Neovim's event loop (libuv) +local packages = {} -- Table of 'name':{options} pairs local function print_res(action, args, ok) local res = ok and 'Paq: ' or 'Paq: Failed to ' @@ -15,7 +14,7 @@ end local function call_git(name, dir, action, ...) local args = {...} local handle - handle = loop.spawn('git', + handle = uv.spawn('git', {args=args, cwd=dir}, vim.schedule_wrap( function(code, signal) @@ -28,7 +27,7 @@ end local function install_pkg(name, dir, isdir, args) if not isdir then - loop.fs_mkdir(dir, loop.fs_stat(PATH).mode) + uv.fs_mkdir(dir, uv.fs_stat(PATH).mode) if args.branch then call_git(name, dir, 'install', 'clone', args.url, '-b', args.branch, '--single-branch', '.') else @@ -54,9 +53,9 @@ end local function rmdir(dir, ispkgdir) local name, t, child, ok - local handle = loop.fs_scandir(dir) + local handle = uv.fs_scandir(dir) while handle do - name, t = loop.fs_scandir_next(handle) + name, t = uv.fs_scandir_next(handle) if not name then break end child = dir .. '/' .. name if ispkgdir then --check which packages are listed @@ -67,11 +66,11 @@ local function rmdir(dir, ispkgdir) print_res('uninstall', name, ok) end else --it's an arbitrary directory or file - ok = (t == 'directory') and rmdir(child) or loop.fs_unlink(child) + ok = (t == 'directory') and rmdir(child) or uv.fs_unlink(child) end if not ok then return end end - return ispkgdir or loop.fs_rmdir(dir) -- Don't delete start or opt + return ispkgdir or uv.fs_rmdir(dir) -- Don't delete start or opt end local function paq(args) From f4d0c3b47751acceb9afdb3407e773bf1a9f3b7b Mon Sep 17 00:00:00 2001 From: Sergio Alejandro Vargas Date: Fri, 20 Nov 2020 12:09:08 -0500 Subject: [PATCH 4/4] Create CONTRIBUTING.md Remove redundant contributing info from readme and docs. --- CONTRIBUTING.md | 21 +++++++++++++++++++++ README.md | 15 ++------------- doc/paq-nvim.txt | 49 ------------------------------------------------ 3 files changed, 23 insertions(+), 62 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c327093 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,21 @@ +# Contributing + +Paq is small because my own needs as a Nvim user are pretty simple, +but that doesn't mean I'm against adding features. If you have suggestions, +write an issue! Try to be specific. When writing the titles, make the intent clear; +and for the body of the issue, the more detailed the description the better. + +For bugs, write the title as an statement: +`Paq isn't doing foo` or `Paq does bar instead of foo`. +In the body, be sure to include the steps necessary to reproduce the issue, +and a minimal working example. + +For feature requests, write the title as an imperative: +`Do foo instead of bar` or `Add foo`. +This makes it easier to match them to their (possible) corresponding PR. +In the body, try to nail down the scope of the feature, what it should do +and what it shouldn't do. Also include if you're interested in adding the +feature yourself. + +For questions, there are no restrictions. Ask away. Just write the title a +question: `Can Paq do foo?` diff --git a/README.md b/README.md index 6ce0c5d..0c23ffa 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Paq is a Neovim package manager written in Lua. Clone this repository: -``` +```sh git clone https://github.com/savq/paq-nvim.git \ "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/paqs/opt/paq-nvim ``` @@ -27,7 +27,7 @@ git clone https://github.com/savq/paq-nvim.git \ ## Usage In your init.vim, you can write something like: -``` +```lua lua << EOF vim.cmd 'packadd paq-nvim' -- Load package @@ -76,14 +76,3 @@ To generate helptags after installing a plugin, just run `:helptags ALL`. The [docs](https://github.com/savq/paq-nvim/tree/master/doc/paq-nvim.txt) include a section on moving from Vim-plug or Minpac to Paq. - - -## Contributing - -Paq is small because my own needs as a Neovim user are pretty simple, -but that doesn't mean I'm against adding features. -If you find a bug, have questions or suggestions, write an issue! - -You can read the [docs](https://github.com/savq/paq-nvim/tree/master/doc/paq-nvim.txt) -section on contributing for more information. - diff --git a/doc/paq-nvim.txt b/doc/paq-nvim.txt index 80912d4..ee11dd0 100644 --- a/doc/paq-nvim.txt +++ b/doc/paq-nvim.txt @@ -15,7 +15,6 @@ CONTENTS *paq-contents* Commands |paq-commands| Paq directory |paq-directory| Moving from other package managers |paq-moving| - Contributing |paq-contributing| ============================================================================== @@ -238,53 +237,5 @@ Would be written in Lua like: paq {'lervag/vimtex', opt=true} < - -============================================================================== -CONTRIBUTING *paq-contributing* - -Paq is small because my own needs as a Nvim user are pretty simple, -but that doesn't mean I'm against adding features. If you have suggestions, -write an issue! - -All development for this package happens on GitHub. When posting an issue -always try to be specific. When writing the titles, make the intent clear; -and for the body of the issue, the more detailed the description the better. - -Also keep in mind the following: - -Bugs~ - -Write the title as an statement: -`Paq isn't doing foo` or `Paq does bar instead of foo` - -In the body, be sure to include the steps necessary to reproduce the issue, -and a minimal working example. - - -Feature requests~ - -For feature requests, write the title as an imperative: -`Do foo instead of bar` or `Add foo` - -This makes it easier to match them to their (possible) corresponding PR. - -In the body, try to nail down the scope of the feature, what it should do -and what it shouldn't do. Also include if you're interested in adding the -feature yourself. - - -Questions~ - -For questions, there are no restrictions. Ask away. Just write the title a -question: `Can Paq do foo?` - - -Showcase~ - -Nvim's Lua support is still a novel thing. If you are using Paq in your Lua -configuration, I'd be interested to see it. Post an issue, or write me an -email. - - ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: