Skip to content

Commit

Permalink
Merge pull request #28 from desdic/20240105toggleterm
Browse files Browse the repository at this point in the history
feature: Add group_id/count for toggleterm
  • Loading branch information
desdic authored Jan 15, 2024
2 parents 5dda62e + b904c15 commit 82d168b
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 49 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Neovim 0.9+ is required
size = nil,
}
},
toggleterm = {
-- default_group_id can be a number or a function that takes a string as parameter.
-- The string passed as parameter is the name of the plugin so its possible to do logic based
-- on plugin name and function should always return a number like:
-- default_group_id = function(plugin) return 1 end
default_group_id = 1,
},
enable = true,
border = "rounded", -- style for vim.ui.selector
style = "minimal",
Expand All @@ -44,6 +51,18 @@ Neovim 0.9+ is required
}
```

Per default all plugins use the same terminal but this behaviour (if you are using `toggleterm`) can be overridden by either grouping the plugins to a specific `group_id` or create a function to assign number based on plugin name.

So if you want all plugins to run under id `id` (default) but the `docker_compose` you would like to have another group you can configure it via

```
extensions = {
docker_compose = { group_id = 2 },
},
```

and now all docker compose's exec is running in a secondary terminal (group_id 2) and all the others in group_id 1

## Extensions

Default `greyjoy` does not have any extensions enabled.
Expand Down
1 change: 1 addition & 0 deletions lua/greyjoy/_extensions/cargo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ M.parse = function(fileinfo)
elem["name"] = name
elem["command"] = cmd
elem["path"] = filepath
elem["plugin"] = "cargo"

table.insert(elements, elem)
end
Expand Down
5 changes: 5 additions & 0 deletions lua/greyjoy/_extensions/docker_compose.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ M.parse = function(fileinfo)
elem["name"] = "docker-compose exec " .. v
elem["command"] = { M.config["cmd"], "exec", "-it", v, M.config["shell"] }
elem["path"] = filepath
elem["plugin"] = "docker_compose"

if M.config["group_id"] then
elem["group_id"] = M.config["group_id"]
end

table.insert(elements, elem)
end
Expand Down
1 change: 1 addition & 0 deletions lua/greyjoy/_extensions/generic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ M.parse = function(fileobj)
elem["name"] = k
elem["command"] = command
elem["path"] = filepath
elem["plugin"] = "generic"

table.insert(globalcommands, elem)
end
Expand Down
1 change: 1 addition & 0 deletions lua/greyjoy/_extensions/kitchen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ M.parse = function(fileinfo)
elem["name"] = "kitchen " .. target .. " " .. v
elem["command"] = { "kitchen", target, v }
elem["path"] = filepath
elem["plugin"] = "kitchen"
table.insert(elements, elem)
end
end
Expand Down
1 change: 1 addition & 0 deletions lua/greyjoy/_extensions/makefile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ M.parse = function(fileinfo)
elem["name"] = "make " .. v
elem["command"] = { "make", v }
elem["path"] = filepath
elem["plugin"] = "makefile"

table.insert(elements, elem)
end
Expand Down
48 changes: 0 additions & 48 deletions lua/greyjoy/_extensions/project.lua

This file was deleted.

1 change: 1 addition & 0 deletions lua/greyjoy/_extensions/vscode_tasks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ M.parse_v2 = function(content, filepath)
elem["name"] = v["label"]
elem["command"] = { v["command"] }
elem["path"] = filepath
elem["plugin"] = "vscode_tasks"

if v["args"] then
for _, value in pairs(v["args"]) do
Expand Down
7 changes: 7 additions & 0 deletions lua/greyjoy/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ local defaults = {
size = nil,
},
},
toggleterm = {
-- default_group_id can be a number or a function that takes a string as parameter.
-- The string passed as parameter is the name of the plugin so its possible to do logic based
-- on plugin name and function should always return a number like:
-- default_group_id = function(plugin) return 1 end
default_group_id = 1,
},
enable = true, -- enable/disable plugin
border = "rounded", -- default borders
style = "minimal", -- default style
Expand Down
22 changes: 21 additions & 1 deletion lua/greyjoy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ greyjoy.menu = function(rootdir, elements)
commands[value["name"]] = {
command = value["command"],
path = value["path"],
group_id = value["group_id"],
plugin = value["plugin"],
}
end

Expand Down Expand Up @@ -107,19 +109,37 @@ greyjoy.to_toggleterm = function(command)
return
end

local count = 1 -- keep old behaviour and have all run in same terminal window
local group_type = type(config.defaults["toggleterm"]["default_group_id"])
if group_type == "number" then
count = config.defaults["toggleterm"]["default_group_id"]
elseif group_type == "function" then
count = config.defaults["toggleterm"]["default_group_id"](command.plugin)
end

if command.group_id ~= nil then
group_type = type(command.group_id)
if group_type == "number" then
count = command.group_id
elseif group_type == "function" then
count = command.group_id(command.plugin)
end
end

local commandstr = table.concat(command.command, " ")
local exec_command = "dir='"
.. command.path
.. "' cmd='"
.. commandstr
.. "'"
.. " name='" .. commandstr .. "'"
if greyjoy.ui.toggleterm.size then
exec_command = "size="
.. greyjoy.ui.toggleterm.size
.. " "
.. exec_command
end
toggleterm.exec_command(exec_command)
toggleterm.exec_command(exec_command, count)
end

greyjoy.to_buffer = function(command)
Expand Down

0 comments on commit 82d168b

Please sign in to comment.