feat: selecting&searching in kitty

This commit is contained in:
Ryan Yin
2023-12-25 12:46:52 +08:00
parent 15727ea482
commit 378319e4bf
5 changed files with 94 additions and 12 deletions

View File

@@ -4,7 +4,6 @@
# general tools
pulumi
pulumictl
# istioctl
# aws
awscli2

View File

@@ -14,9 +14,9 @@
# 4. Increase Font Size: `command + =` | `command + +`
# 5. Decrease Font Size: `command + -` | `command + _`
# 6. And Other common shortcuts such as Copy, Paste, Cursor Move, etc.
# 7. Search in the current window(show_scrollback): `ctrl + shift + h`
# 7. Search/Select in the current window(show_scrollback): `ctrl + shift + f`
# This will open a pager, it's defined by `scrollback_pager`, default is `less`
#
# https://sw.kovidgoyal.net/kitty/overview/#the-scrollback-buffer
#
# Useful Hot Keys for Linux:
# 1. New Tab: `ctrl + shift + t`
@@ -45,6 +45,17 @@
keybindings = {
"ctrl+shift+m" = "toggle_maximized";
"ctrl+shift+f" = "show_scrollback"; # search in the current window
"cmd+f" = "show_scrollback";
# Switch to tab 1-8
"ctrl+alt+1" = "goto_tab 1";
"ctrl+alt+2" = "goto_tab 2";
"ctrl+alt+3" = "goto_tab 3";
"ctrl+alt+4" = "goto_tab 4";
"ctrl+alt+5" = "goto_tab 5";
"ctrl+alt+6" = "goto_tab 6";
"ctrl+alt+7" = "goto_tab 7";
"ctrl+alt+8" = "goto_tab 8";
};
settings = {
@@ -58,6 +69,13 @@
# 2. https://github.com/ryan4yin/nix-config/issues/8
# Spawn a nushell in login mode via `bash`
shell = "${pkgs.bash}/bin/bash --login -c 'nu --login --interactive'";
# for selecting/searching in the current window
# https://github.com/kovidgoyal/kitty/issues/719
scrollback_pager = ''$SHELL -c 'nvim -u NONE -R -M -u ${./kitty_pager.lua} -c "lua kitty_pager(INPUT_LINE_NUMBER, CURSOR_LINE, CURSOR_COLUMN)" -' '';
# for active tab
active_tab_title_template = "{fmt.fg.green}{bell_symbol}{activity_symbol}{fmt.fg.tab}{index}:{title}";
# for inactive tab
tab_title_template = "{fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{index}:{title}";
};
# macOS specific settings

View File

@@ -0,0 +1,62 @@
kitty_pager = function(INPUT_LINE_NUMBER, CURSOR_LINE, CURSOR_COLUMN)
print('kitty sent:', INPUT_LINE_NUMBER, CURSOR_LINE, CURSOR_COLUMN)
vim.opt.encoding='utf-8'
vim.opt.clipboard = 'unnamed'
vim.opt.compatible = false
vim.opt.number = false
vim.opt.relativenumber = false
vim.opt.termguicolors = true
vim.opt.showmode = false
vim.opt.ruler = false
vim.opt.laststatus = 0
vim.o.cmdheight = 0
vim.opt.showcmd = false
vim.opt.scrollback = INPUT_LINE_NUMBER + CURSOR_LINE
local term_buf = vim.api.nvim_create_buf(true, false);
local term_io = vim.api.nvim_open_term(term_buf, {})
vim.api.nvim_buf_set_keymap(term_buf, 'n', 'q', '<Cmd>q<CR>', { })
vim.api.nvim_buf_set_keymap(term_buf, 'n', '<ESC>', '<Cmd>q<CR>', { })
local group = vim.api.nvim_create_augroup('kitty+page', {})
local setCursor = function()
vim.api.nvim_feedkeys(tostring(INPUT_LINE_NUMBER) .. [[ggzt]], 'n', true)
local line = vim.api.nvim_buf_line_count(term_buf)
if (CURSOR_LINE <= line) then
line = CURSOR_LINE
end
vim.api.nvim_feedkeys(tostring(line - 1) .. [[j]], 'n', true)
vim.api.nvim_feedkeys([[0]], 'n', true)
vim.api.nvim_feedkeys(tostring(CURSOR_COLUMN - 1) .. [[l]], 'n', true)
end
vim.api.nvim_create_autocmd('ModeChanged', {
group = group,
buffer = term_buf,
callback = function()
local mode = vim.fn.mode()
if mode == 't' then
vim.cmd.stopinsert()
vim.schedule(setCursor)
end
end,
})
vim.api.nvim_create_autocmd('VimEnter', {
group = group,
pattern = '*',
once = true,
callback = function(ev)
local current_win = vim.fn.win_getid()
for _, line in ipairs(vim.api.nvim_buf_get_lines(ev.buf, 0, -2, false)) do
vim.api.nvim_chan_send(term_io, line)
vim.api.nvim_chan_send(term_io, '\r\n')
end
for _, line in ipairs(vim.api.nvim_buf_get_lines(ev.buf, -2, -1, false)) do
vim.api.nvim_chan_send(term_io, line)
end
vim.api.nvim_win_set_buf(current_win, term_buf)
vim.api.nvim_buf_delete(ev.buf, { force = true } )
vim.schedule(setCursor)
end
})
end

View File

@@ -1,3 +1,4 @@
# https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix
{lib, ...}: {
# Generate an attribute set from a list.
#

View File

@@ -6,13 +6,15 @@
scanPaths = path:
builtins.map
(f: (path + "/${f}"))
(builtins.filter # find all overlay files in the current directory
(
f:
f
!= "default.nix" # ignore default.nix
&& f != "README.md" # ignore README.md
)
(builtins.attrNames (builtins.readDir path)));
(builtins.attrNames
(lib.attrsets.filterAttrs
(
path: _type:
(_type == "directory") # include directories
|| (
(path != "default.nix") # ignore default.nix
&& (lib.strings.hasSuffix ".nix" path) # include .nix files
)
)
(builtins.readDir path)));
}