diff --git a/home/base/desktop/cloud/default.nix b/home/base/desktop/cloud/default.nix index a96e90da..42844bbe 100644 --- a/home/base/desktop/cloud/default.nix +++ b/home/base/desktop/cloud/default.nix @@ -4,7 +4,6 @@ # general tools pulumi pulumictl - # istioctl # aws awscli2 diff --git a/home/base/desktop/terminal/kitty.nix b/home/base/desktop/terminal/kitty.nix index 92c50283..62bdaddf 100644 --- a/home/base/desktop/terminal/kitty.nix +++ b/home/base/desktop/terminal/kitty.nix @@ -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 diff --git a/home/base/desktop/terminal/kitty_pager.lua b/home/base/desktop/terminal/kitty_pager.lua new file mode 100644 index 00000000..0fc65ddc --- /dev/null +++ b/home/base/desktop/terminal/kitty_pager.lua @@ -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', 'q', { }) + vim.api.nvim_buf_set_keymap(term_buf, 'n', '', 'q', { }) + 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 diff --git a/lib/attrs.nix b/lib/attrs.nix index 6421e095..52e6d69f 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -1,3 +1,4 @@ +# https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix {lib, ...}: { # Generate an attribute set from a list. # diff --git a/lib/default.nix b/lib/default.nix index ce4fce09..0d295431 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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))); }