Skip to content

Commit

Permalink
feat: execute run hook as vim command if first char is ':'
Browse files Browse the repository at this point in the history
  • Loading branch information
saccarosium authored and savq committed Jun 10, 2023
1 parent 295fbf1 commit c3573d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require "paq" {

{ "lervag/vimtex", opt = true }, -- Use braces when passing options

{ 'nvim-treesitter/nvim-treesitter', run = function() vim.cmd 'TSUpdate' end },
{ 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' },
}
```

Expand Down
3 changes: 2 additions & 1 deletion doc/paq-nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ The options and their types are the following:
updating a package. Useful for packages that require extra build steps.

If a string, Paq will execute the string as a shell command in the
directory of the package (not in the current directory).
directory of the package (not in the current directory). If the first
character of the string is a `:`, it will be execute as vim `:command`

If a function, Paq will execute the function right after installing
the package. The function cannot take any arguments.
Expand Down
18 changes: 11 additions & 7 deletions lua/paq.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ local function run_hook(pkg, counter, sync)
return counter and counter(pkg.name, res, sync)
elseif t == "string" then
local args = {}
for word in pkg.run:gmatch("%S+") do
table.insert(args, word)
if pkg.run:sub(1, 1) == ":" then
vim.cmd(pkg.run)
else
for word in pkg.run:gmatch("%S+") do
table.insert(args, word)
end
call_proc(table.remove(args, 1), args, pkg.dir, function(ok)
local res = ok and "ok" or "err"
report("hook", pkg.name, res)
return counter and counter(pkg.name, res, sync)
end)
end
call_proc(table.remove(args, 1), args, pkg.dir, function(ok)
local res = ok and "ok" or "err"
report("hook", pkg.name, res)
return counter and counter(pkg.name, res, sync)
end)
return true
end
end
Expand Down

0 comments on commit c3573d7

Please sign in to comment.