From c3573d74ed6a38523ffb58e72e90b40b6ffdce0d Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Mon, 29 May 2023 18:33:20 +0200 Subject: [PATCH] feat: execute run hook as vim command if first char is ':' --- README.md | 2 +- doc/paq-nvim.txt | 3 ++- lua/paq.lua | 18 +++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ba90028..8cb2b1e 100644 --- a/README.md +++ b/README.md @@ -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' }, } ``` diff --git a/doc/paq-nvim.txt b/doc/paq-nvim.txt index f45840b..9f16ad2 100644 --- a/doc/paq-nvim.txt +++ b/doc/paq-nvim.txt @@ -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. diff --git a/lua/paq.lua b/lua/paq.lua index 72f15e9..c19109a 100644 --- a/lua/paq.lua +++ b/lua/paq.lua @@ -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