Skip to content

Commit

Permalink
Merge branch 'setup-config' into breaking-setup-config
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh committed Oct 1, 2023
2 parents 3dcb0d1 + f2af540 commit 2b39dba
Show file tree
Hide file tree
Showing 44 changed files with 524 additions and 595 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ sh -c "$(curl -s https://raw.githubusercontent.com/mikesmithgh/kitty-scrollback.
enabled = true,
lazy = true,
cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' },
event = { 'User KittyScrollbackLaunch' },
-- version = '*', -- latest stable version, may have breaking changes if major version changed
-- version = '^1.0.0', -- pin major version, include fixes and features that do not have breaking changes
config = function()
Expand All @@ -115,6 +116,7 @@ sh -c "$(curl -s https://raw.githubusercontent.com/mikesmithgh/kitty-scrollback.
disable = false,
opt = true,
cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' },
event = { 'User KittyScrollbackLaunch' },
-- tag = '*', -- latest stable version, may have breaking changes if major version changed
-- tag = 'v1.0.0', -- pin specific tag
config = function()
Expand Down Expand Up @@ -203,14 +205,14 @@ listen_on unix:/tmp/kitty
shell_integration enabled

# kitty-scrollback.nvim Kitten alias
action_alias kitty_scrollback_nvim kitten /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --cwd /Users/mike/gitrepos/kitty-scrollback.nvim/lua/kitty-scrollback/configs
action_alias kitty_scrollback_nvim kitten /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py

# Browse scrollback buffer in nvim
map ctrl+shift+h kitty_scrollback_nvim
# Browse output of the last shell command in nvim
map ctrl+shift+g kitty_scrollback_nvim --config-file get_text_last_cmd_output.lua
map ctrl+shift+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
# Show clicked command output in nvim
mouse_map ctrl+shift+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config-file get_text_last_visited_cmd_output.lua
mouse_map ctrl+shift+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_visited_cmd_output
```

</details>
Expand All @@ -220,7 +222,7 @@ Arguments that can be passed to the `kitty_scrollback_nvim` Kitten defined in [k

| Argument | Description |
| :--------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--config-file` | `kitty-scrollback.nvim` plugin configuration file. The configuration file must return a Lua table with the function `config(kitty_data): table`. You may specify multiple config files that will merge all configuration options. |
| `--config` | The name of the `kitty-scrollback.nvim` plugin configuration. The configuration can be defined during plugin setup (i.e., `require('kitty-scrollback').setup({ ... })`). |
| `--no-nvim-args` | Do not provide any arguments to the Neovim instance that displays the scrollback buffer. The default arguments passed to Neovim are `--clean --noplugin -n`. This flag removes those options. |
| `--nvim-args` | All arguments after this flag are passed to the Neovim instance that displays the scrollback buffer. This must be the last of the `kitty-scrollback.nvim` Kitten arguments that are configured. Otherwise, you may unintentionally send the wrong arguments to Neovim. The default arguments passed to Neovim are `--clean --noplugin -n`. This flag removes those options. |
| `--env` | Environment variable that is passed to the Neovim instance that displays the scrollback buffer. Format is `--env var_name=var_value`. You may specify multiple config files that will merge all configuration options. Useful for setting `NVIM_APPNAME` |
Expand Down
92 changes: 45 additions & 47 deletions lua/kitty-scrollback/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,53 +71,57 @@ end
M.generate_kittens = function(all)
local kitty_scrollback_kitten =
vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1]
local kitty_scrollback_configs =
vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs', false)[1]
local example_path =
vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/example.lua', false)[1]

local ksb_configs = { '' }
local action_alias = 'kitty_scrollback_nvim'
local top_ksb_configs = {
local builtin_configs = {
'# kitty-scrollback.nvim Kitten alias',
'action_alias '
.. action_alias
.. ' kitten '
.. kitty_scrollback_kitten
.. ' --cwd '
.. kitty_scrollback_configs,
'action_alias ' .. action_alias .. ' kitten ' .. kitty_scrollback_kitten,
'',
'# Browse scrollback buffer in nvim',
'map ctrl+shift+h ' .. action_alias,
}
for _, c in pairs(vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/*.lua', true)) do
local name = vim.fn.fnamemodify(c, ':t:r')
local ksb_config = require('kitty-scrollback.configs.' .. name).config() or {}
local keymap = ksb_config.kitty_keymap
local config = (keymap or 'map f1')
.. ' '
'# Browse output of the last shell command in nvim',
'map ctrl+shift+g ' .. action_alias .. ' --config ksb_builtin_last_cmd_output',
'# Show clicked command output in nvim',
'mouse_map ctrl+shift+right press ungrabbed combine : mouse_select_command_output : '
.. action_alias
.. ' --config-file '
.. name
.. '.lua'
table.insert(top_ksb_configs, ksb_config.kitty_keymap_description)
if keymap then
table.insert(top_ksb_configs, config)
else
table.insert(ksb_configs, config)
end
end
.. ' --config ksb_builtin_last_visited_cmd_output',
}

local ksb_example = require('kitty-scrollback.configs.example').configs
local example_configs = vim.tbl_map(
function(name)
if name == '' or name:match('^#.*') then
return name
end
return 'map f1 ' .. action_alias .. ' --config ' .. name
end,
vim.list_extend({
'',
'# Example kitty-scrollback.nvim config overrides',
'# See ' .. example_path .. ' for config details',
}, vim.tbl_keys(ksb_example))
)

local nvim_args = vim.tbl_map(function(c)
if c == '' or c:match('^#.*') then
return c
end
return 'map f1 ' .. action_alias .. ' ' .. c
end, {
[[]],
[[# Example kitty-scrollback.nvim nvim overrides]],
[[--no-nvim-args --env NVIM_APPNAME=ksb-nvim]],
[[--nvim-args +'colorscheme tokyonight']],
[[--nvim-args +'lua vim.defer_fn(function() vim.api.nvim_set_option_value("filetype", "markdown", { buf = 0 }); vim.cmd("silent! CellularAutomaton make_it_rain") end, 1000)']],
})

local kitten_configs = vim.list_extend(
vim.list_extend(vim.tbl_extend('force', top_ksb_configs, {}), ksb_configs),
vim.list_extend(vim.tbl_extend('force', builtin_configs, {}), example_configs),
nvim_args
)

local bufid = vim.api.nvim_create_buf(true, true)
vim.api.nvim_set_option_value('filetype', 'kitty', {
buf = bufid,
Expand All @@ -126,31 +130,25 @@ M.generate_kittens = function(all)
if all then
vim.api.nvim_buf_set_lines(bufid, 0, -1, false, kitten_configs)
else
vim.api.nvim_buf_set_lines(bufid, 0, -1, false, top_ksb_configs)
vim.api.nvim_buf_set_lines(bufid, 0, -1, false, builtin_configs)
end
end

M.checkhealth = function()
local kitty_scrollback_kitten =
vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1]
local checkhealth_config =
vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/checkhealth.lua', false)[1]
if
not (
vim.fn.has('nvim-0.10') > 0
and vim
.system({
'kitty',
'@',
'kitten',
kitty_scrollback_kitten,
'--config-file',
checkhealth_config,
})
:wait().code
== 0
)
then
if vim.fn.has('nvim-0.10') > 0 then
vim
.system({
'kitty',
'@',
'kitten',
kitty_scrollback_kitten,
'--config',
'ksb_builtin_checkhealth',
})
:wait()
else
-- fallback on checkhealth for earlier versions of nvim
vim.cmd.checkhealth('kitty-scrollback')
end
Expand Down
27 changes: 27 additions & 0 deletions lua/kitty-scrollback/configs/builtin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local prefix = 'ksb_builtin_'

return {
configs = {
[prefix .. 'last_cmd_output'] = function()
return {
kitty_get_text = {
extent = 'last_cmd_output',
ansi = true,
},
}
end,
[prefix .. 'last_visited_cmd_output'] = function()
return {
kitty_get_text = {
extent = 'last_visited_cmd_output',
ansi = true,
},
}
end,
[prefix .. 'checkhealth'] = function()
return {
checkhealth = true,
}
end,
},
}
51 changes: 0 additions & 51 deletions lua/kitty-scrollback/configs/callbacks.lua

This file was deleted.

9 changes: 0 additions & 9 deletions lua/kitty-scrollback/configs/checkhealth.lua

This file was deleted.

Loading

0 comments on commit 2b39dba

Please sign in to comment.