Skip to content

Commit

Permalink
feat: add subcommands to :GhActions
Browse files Browse the repository at this point in the history
This introduces the following commands:

- `:GhActions` or `:GhActions toggle` toggles the `gh-actions` split
- `:GhActions open` opens the `gh-actions` split
- `:GhActions close` closes the `gh-actions` split

BREAKING CHANGE: `:GhActions` now toggles the split instead of only opening it.

Fixes #12
  • Loading branch information
topaxi committed Oct 24, 2024
1 parent b8d4ff7 commit 5885942
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ Alternatively, define a `GITHUB_TOKEN` variable in your environment.

### Commands

- `:GhActions` opens the `gh-actions` split
- `:GhActions` or `:GhActions toggle` toggles the `gh-actions` split
- `:GhActions open` opens the `gh-actions` split
- `:GhActions close` closes the `gh-actions` split

### Keybindings

Expand Down
38 changes: 38 additions & 0 deletions lua/gh-actions/command.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
local M = {}

function handle_gh_actions_command(a)
local gha = require('gh-actions')

local action = a.fargs[1] or 'toggle'

if action == 'open' then
return gha.open()
elseif action == 'close' then
return gha.close()
elseif action == 'toggle' then
local ui = require('gh-actions.ui')

if ui.split.winid then
return gha.close()
else
return gha.open()
end
end
end

function completion_customlist()
return {
'open',
'close',
'toggle',
}
end

function M.setup()
vim.api.nvim_create_user_command('GhActions', handle_gh_actions_command, {
nargs = '?',
complete = completion_customlist,
})
end

return M
3 changes: 1 addition & 2 deletions lua/gh-actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function M.setup(opts)

require('gh-actions.config').setup(opts)
require('gh-actions.ui').setup()

vim.api.nvim_create_user_command('GhActions', M.open, {})
require('gh-actions.command').setup()
end

--TODO Only periodically fetch all workflows
Expand Down

0 comments on commit 5885942

Please sign in to comment.