Skip to content

Commit 6d8ed07

Browse files
committed
Refactored ghdash to gh_dash and command changes
1 parent 1e44359 commit 6d8ed07

6 files changed

Lines changed: 63 additions & 64 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
> Latest version: ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/johnseth97/gh-dash.nvim?sort=semver)
55
66
### Features:
7-
- ✅ Toggle gh-dash floating window with `:ghdash-toggle`
7+
- ✅ Toggle gh-dash floating window with `:GHDashToggle`
88
- ✅ Optional keymap mapping via `setup` call
99
- ✅ Background running when window hidden
10-
- ✅ Statusline integration via `require('ghdash').status()`
10+
- ✅ Statusline integration via `require('gh_dash').status()`
1111

1212
### Installation:
1313

@@ -34,7 +34,7 @@ return {
3434
keys = {
3535
{
3636
'<leader>cc',
37-
function() require('gh-dash').toggle() end,
37+
function() require('gh_dash').toggle() end,
3838
desc = 'Toggle gh-dash popup',
3939
},
4040
},
@@ -50,7 +50,7 @@ return {
5050
- If you are not using Lazy, I assume you can figure out how to install the plugin yourself by cloning the repo.
5151

5252
### Usage:
53-
- Call `:gh-dash` (or `:gh-dashToggle`) to open or close the gh-dash popup.
53+
- Call `:GHDash` (or `:GHDashToggle`) to open or close the gh-dash popup.
5454
-- Map your own keybindings via the `keymaps.toggle` setting.
5555
- Add the following code to show presence of backgrounded gh-dash window in lualine:
5656
```lua

lua/gh_dash/init.lua

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local config = {
88
width = 0.8,
99
height = 0.8,
1010
cmd = { 'gh', 'dash' },
11-
-- whether to auto-install the ghdash TUI not found (requires npm)
11+
-- whether to auto-install the gh_dash TUI not found (requires npm)
1212
autoinstall = false,
1313
}
1414

@@ -20,20 +20,20 @@ local state = {
2020

2121
function M.setup(user_config)
2222
config = vim.tbl_deep_extend('force', config, user_config or {})
23-
-- define commands for toggling the ghdash popup
24-
vim.api.nvim_create_user_command('ghdash', function()
23+
-- define commands for toggling the gh_dash popup
24+
vim.api.nvim_create_user_command('GHdash', function()
2525
M.toggle()
26-
end, { desc = 'Toggle ghdash popup' })
27-
vim.api.nvim_create_user_command('ghdash-toggle', function()
26+
end, { desc = 'Toggle gh-dash popup' })
27+
vim.api.nvim_create_user_command('GHdashToggle', function()
2828
M.toggle()
29-
end, { desc = 'Toggle ghdash popup (alias)' })
29+
end, { desc = 'Toggle gh-dash popup (alias)' })
3030
-- optional keymap for toggle
3131
if config.keymaps.toggle then
32-
vim.api.nvim_set_keymap('n', config.keymaps.toggle, '<cmd>ghdash-toggle<CR>', { noremap = true, silent = true })
32+
vim.api.nvim_set_keymap('n', config.keymaps.toggle, '<cmd>GHDashToggle<CR>', { noremap = true, silent = true })
3333
end
3434
end
3535

36-
-- Create a floating window displaying the ghdash buffer
36+
-- Create a floating window displaying the gh_dash buffer
3737
local function open_window()
3838
-- compute dimensions and position
3939
local width = math.floor(vim.o.columns * config.width)
@@ -101,10 +101,10 @@ function M.open()
101101
-- buffer options
102102
vim.api.nvim_buf_set_option(state.buf, 'bufhidden', 'hide')
103103
vim.api.nvim_buf_set_option(state.buf, 'swapfile', false)
104-
vim.api.nvim_buf_set_option(state.buf, 'filetype', 'ghdash')
105-
-- map <Esc> in terminal and normal modes to close the ghdash window
106-
vim.api.nvim_buf_set_keymap(state.buf, 't', '<Esc>', [[<C-\><C-n><cmd>lua require('ghdash').close()<CR>]], { noremap = true, silent = true })
107-
vim.api.nvim_buf_set_keymap(state.buf, 'n', '<Esc>', [[<cmd>lua require('ghdash').close()<CR>]], { noremap = true, silent = true })
104+
vim.api.nvim_buf_set_option(state.buf, 'filetype', 'gh_dash')
105+
-- map <Esc> in terminal and normal modes to close the gh_dash window
106+
vim.api.nvim_buf_set_keymap(state.buf, 't', '<Esc>', [[<C-\><C-n><cmd>lua require('gh_dash').close()<CR>]], { noremap = true, silent = true })
107+
vim.api.nvim_buf_set_keymap(state.buf, 'n', '<Esc>', [[<cmd>lua require('gh_dash').close()<CR>]], { noremap = true, silent = true })
108108
end
109109
open_window()
110110
-- determine if config.cmd is a simple executable name (no args) for checking
@@ -127,52 +127,52 @@ function M.open()
127127
local cmd = {
128128
shell_cmd,
129129
'-c',
130-
"echo 'Autoinstalling OpenAI ghdash via npm...'; npm install -g @openai/ghdash",
130+
"echo 'Autoinstalling OpenAI gh_dash via npm...'; npm install -g @openai/gh_dash",
131131
}
132132
state.job = vim.fn.termopen(cmd, {
133133
cwd = vim.loop.cwd(),
134134
on_exit = function(_, exit_code)
135135
if exit_code == 0 then
136-
vim.notify('[ghdash.nvim] ghdash CLI installed successfully', vim.log.levels.INFO)
137-
-- automatically re-launch ghdash CLI now that it's installed
136+
vim.notify('[gh_dash.nvim] gh_dash CLI installed successfully', vim.log.levels.INFO)
137+
-- automatically re-launch gh_dash CLI now that it's installed
138138
vim.schedule(function()
139139
M.close()
140140
state.buf = nil
141141
M.open()
142142
end)
143143
else
144-
vim.notify('[ghdash.nvim] failed to install ghdash CLI', vim.log.levels.ERROR)
144+
vim.notify('[gh_dash.nvim] failed to install gh_dash CLI', vim.log.levels.ERROR)
145145
end
146146
state.job = nil
147147
end,
148148
})
149149
end
150150
else
151-
-- show installation instructions in the ghdash popup
151+
-- show installation instructions in the gh_dash popup
152152
local msg = {
153-
'npm not found; cannot auto-install ghdash CLI.',
153+
'npm not found; cannot auto-install gh_dash CLI.',
154154
'',
155155
'Please install via your system package manager, or manually run:',
156-
' npm install -g @openai/ghdash',
156+
' npm install -g @openai/gh_dash',
157157
}
158158
vim.api.nvim_buf_set_lines(state.buf, 0, -1, false, msg)
159159
end
160160
else
161161
-- show instructions inline when autoinstall is disabled
162162
local msg = {
163-
'ghdash CLI not found.',
163+
'gh_dash CLI not found.',
164164
'',
165165
'Install with:',
166-
' npm install -g @openai/ghdash',
166+
' npm install -g @openai/gh_dash',
167167
'',
168168
'Or enable autoinstall in your plugin setup:',
169-
' require("ghdash").setup{ autoinstall = true }',
169+
' require("gh_dash").setup{ autoinstall = true }',
170170
}
171171
vim.api.nvim_buf_set_lines(state.buf, 0, -1, false, msg)
172172
end
173173
return
174174
end
175-
-- spawn the ghdash CLI in the floating terminal buffer
175+
-- spawn the gh_dash CLI in the floating terminal buffer
176176
if not state.job then
177177
state.job = vim.fn.termopen(config.cmd, {
178178
cwd = vim.loop.cwd(),
@@ -200,20 +200,20 @@ end
200200

201201
function M.statusline()
202202
if state.job and not (state.win and vim.api.nvim_win_is_valid(state.win)) then
203-
return '[ghdash]'
203+
return '[gh_dash]'
204204
end
205205
return ''
206206
end
207207

208-
--- Return a lualine.nvim component for displaying ghdash status
209-
-- Usage: table.insert(opts.sections.lualine_x, require('ghdash').status())
208+
--- Return a lualine.nvim component for displaying gh_dash status
209+
-- Usage: table.insert(opts.sections.lualine_x, require('gh_dash').status())
210210
function M.status()
211211
return {
212212
-- component function
213213
function()
214214
return M.statusline()
215215
end,
216-
-- only show when ghdash job is running in background
216+
-- only show when gh_dash job is running in background
217217
cond = function()
218218
return M.statusline() ~= ''
219219
end,

plugin/gh_dash.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
local ok, ghdash = pcall(require, 'ghdash')
1+
local ok, gh_dash = pcall(require, 'gh_dash')
22
if not ok then
33
return
44
end
5-
ghdash.setup()
6-
5+
gh_dash.setup()

tests/gh_dash_spec.lua

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
-- tests/ghdash_spec.lua
1+
-- tests/gh_dash_spec.lua
22
-- luacheck: globals describe it assert eq
33
-- luacheck: ignore a -- “a” is imported but unused
44
local a = require 'plenary.async.tests'
55
local eq = assert.equals
66

7-
describe('ghdash.nvim', function()
7+
describe('gh_dash.nvim', function()
88
before_each(function()
99
vim.cmd 'set noswapfile' -- prevent side effects
10-
vim.cmd 'silent! bwipeout!' -- close any open ghdash windows
10+
vim.cmd 'silent! bwipeout!' -- close any open gh_dash windows
1111
end)
1212

1313
it('loads the module', function()
14-
local ok, ghdash = pcall(require, 'ghdash')
15-
assert(ok, 'ghdash module failed to load')
16-
assert(ghdash.open, 'ghdash.open missing')
17-
assert(ghdash.close, 'ghdash.close missing')
18-
assert(ghdash.toggle, 'ghdash.toggle missing')
14+
local ok, gh_dash = pcall(require, 'gh_dash')
15+
assert(ok, 'gh_dash module failed to load')
16+
assert(gh_dash.open, 'gh_dash.open missing')
17+
assert(gh_dash.close, 'gh_dash.close missing')
18+
assert(gh_dash.toggle, 'gh_dash.toggle missing')
1919
end)
2020

21-
it('creates ghdash commands', function()
22-
require('ghdash').setup { keymaps = {} }
21+
it('creates gh_dash commands', function()
22+
require('gh_dash').setup { keymaps = {} }
2323

2424
local cmds = vim.api.nvim_get_commands {}
25-
assert(cmds['ghdash'], 'ghdash command not found')
26-
assert(cmds['ghdashToggle'], 'ghdashToggle command not found')
25+
assert(cmds['gh_dash'], 'gh_dash command not found')
26+
assert(cmds['gh_dashToggle'], 'gh_dashToggle command not found')
2727
end)
2828

2929
it('opens a floating terminal window', function()
30-
require('ghdash').setup { cmd = "echo 'test'" }
31-
require('ghdash').open()
30+
require('gh_dash').setup { cmd = "echo 'test'" }
31+
require('gh_dash').open()
3232

3333
local win = vim.api.nvim_get_current_win()
3434
local buf = vim.api.nvim_win_get_buf(win)
3535
local ft = vim.api.nvim_buf_get_option(buf, 'filetype')
36-
eq(ft, 'ghdash')
36+
eq(ft, 'gh_dash')
3737

38-
require('ghdash').close()
38+
require('gh_dash').close()
3939
end)
4040

4141
it('toggles the window', function()
42-
require('ghdash').setup { cmd = "echo 'test'" }
42+
require('gh_dash').setup { cmd = "echo 'test'" }
4343

44-
require('ghdash').toggle()
44+
require('gh_dash').toggle()
4545
local win1 = vim.api.nvim_get_current_win()
46-
assert(vim.api.nvim_win_is_valid(win1), 'ghdash window should be open')
46+
assert(vim.api.nvim_win_is_valid(win1), 'gh_dash window should be open')
4747

48-
require('ghdash').toggle()
48+
require('gh_dash').toggle()
4949
local still_valid = pcall(vim.api.nvim_win_get_buf, win1)
50-
assert(not still_valid, 'ghdash window should be closed')
50+
assert(not still_valid, 'gh_dash window should be closed')
5151
end)
5252

5353
it('shows statusline only when job is active but window is not', function()
54-
require('ghdash').setup { cmd = 'sleep 1000' }
55-
require('ghdash').open()
54+
require('gh_dash').setup { cmd = 'sleep 1000' }
55+
require('gh_dash').open()
5656

5757
vim.defer_fn(function()
58-
require('ghdash').close()
59-
local status = require('ghdash').statusline()
60-
eq(status, '[ghdash]')
58+
require('gh_dash').close()
59+
local status = require('gh_dash').statusline()
60+
eq(status, '[gh_dash]')
6161
end, 100)
6262
end)
6363
end)

tests/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
-- luacheck: ignore async
44
local async = require 'plenary.async.tests'
55

6-
describe('ghdash.nvim', function()
6+
describe('gh_dash.nvim', function()
77
it('should load without errors', function()
8-
require 'ghdash'
8+
require 'gh_dash'
99
end)
1010

1111
it('should respond to basic command', function()
12-
vim.cmd 'ghdash'
12+
vim.cmd 'gh_dash'
1313
-- Add assertion if it triggers some output or state change
1414
end)
1515
end)

tests/minimal_init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
vim.cmd 'set rtp+=.'
22
vim.cmd 'set rtp+=./plenary.nvim' -- if using as a submodule or symlinked
3-
require 'plugin.ghdash' -- triggers plugin/ghdash.lua
3+
require 'plugin.gh_dash' -- triggers plugin/gh_dash.lua

0 commit comments

Comments
 (0)