diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b91621ac..951abe83 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -81,7 +81,7 @@ jobs: if: ${{ !(inputs.enable_debug_tmate || inputs.enable_debug_vnc) || (inputs.debug_kitty_version == matrix.kitty_version && inputs.debug_nvim_version == matrix.nvim_version) }} run: | sudo apt update - sudo apt install -y xfce4 libxcb-xkb1 xsel tmux fish + sudo apt install -y xfce4 libxcb-xkb1 xsel tmux fish zsh # homebrew is not used but is required to reproduce an issue for a test case /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" diff --git a/README.md b/README.md index dd087caf..627e46c0 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Navigate your [Kitty](https://sw.kovidgoyal.net/kitty/) scrollback buffer to qui - 🫑 [Commands](#-commands) - ⌨️ [Keymaps](#%EF%B8%8F-keymaps) - πŸͺ› [Optional Setup](#-optional-setup) + - [Command-line editing](#command-line-editing) - [tmux (πŸ§ͺ experimental )](#tmux--experimental-) - πŸ‘ [Recommendations](#-recommendations) - 🀝 [Acknowledgements](#-acknowledgements) @@ -168,11 +169,27 @@ Navigate your [Kitty](https://sw.kovidgoyal.net/kitty/) scrollback buffer to qui - `kitty-scrollback.nvim` automatically closes and executes the content of the paste window +
+😹 Edit the current command line (bash, fish, or zsh) + +https://github.com/user-attachments/assets/6b4f177f-34c2-4ce7-9adb-15e0d3e19498 + +This requires extra steps to setup. See optional [Command-line editing setup](#command-line-editing). + +- Start typing a command in your shell +- Open the current command line in kitty-scrollback.nvim with the following keybind + - bash: `` + - fish: `` or `` (where `M` is the alt key) + - zsh: `` +- Modify the command and do any additional operations that you typically would perform in kitty-scrollback.nvim +
😾 tmux support (πŸ§ͺ experimental ) +This requires extra steps to setup. See optional [tmux setup](#tmux--experimental-). + - Open a tmux pane's scrollback history (default mapping `[`) - That's it! You are in Neovim, navigate the scrollback buffer. @@ -258,7 +275,7 @@ sh -c "$(curl -s https://raw.githubusercontent.com/mikesmithgh/kitty-scrollback. 'mikesmithgh/kitty-scrollback.nvim', enabled = true, lazy = true, - cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' }, + cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing' }, event = { 'User KittyScrollbackLaunch' }, -- version = '*', -- latest stable version, may have breaking changes if major version changed -- version = '^6.0.0', -- pin major version, include fixes and features that do not have breaking changes @@ -278,7 +295,7 @@ sh -c "$(curl -s https://raw.githubusercontent.com/mikesmithgh/kitty-scrollback. 'mikesmithgh/kitty-scrollback.nvim', disable = false, opt = true, - cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' }, + cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing' }, event = { 'User KittyScrollbackLaunch' }, -- tag = '*', -- latest stable version, may have breaking changes if major version changed -- tag = 'v6.0.0', -- pin specific tag @@ -760,7 +777,7 @@ require("lazy").setup({ "mikesmithgh/kitty-scrollback.nvim", enabled = true, lazy = true, - cmd = { "KittyScrollbackGenerateKittens", "KittyScrollbackCheckHealth" }, + cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing' }, event = { "User KittyScrollbackLaunch" }, config = function() require("kitty-scrollback").setup({ @@ -787,7 +804,10 @@ action_alias kitty_scrollback_nvim kitten /path/to/your/install/kitty-scrollback ``` ## 🧬 Environment Variables -The environment variable `KITTY_SCROLLBACK_NVIM` is set to `true` while kitty-scrollback.nvim is active. +The environment variable `KITTY_SCROLLBACK_NVIM` is set to `'true'` while kitty-scrollback.nvim is active. +> [!NOTE] +> `'true'` is a string because `KITTY_SCROLLBACK_NVIM` is an environment variable. Make sure to use a string `'true'` in Lua +> instead of accidentally using a boolean `true`. Otherwise, the conditional checks will not operate as expected. This can be used to in your Neovim configuration to provide kitty-scrollback.nvim specific behavior that may differ from a regular Neovim instance. ```lua @@ -831,10 +851,11 @@ require('kitty-scrollback').setup({ ## 🫑 Commands The API is available via the `kitty-scrollback.api` module. e.g., `require('kitty-scrollback.api')` -| Command | API | Description | -| :-------------------------------------------------- | :----------------------------------------------------- | :---------------------------------------------------------------------- | -| `:KittyScrollbackGenerateKittens [generate_modes]` | `generate_kittens(table)?` | Generate Kitten commands used as reference for configuring `kitty.conf` | -| `:KittyScrollbackCheckHealth` | `checkhealth()` | Run `:checkhealth kitty-scrollback` in the context of Kitty | +| Command | API | Description | +| :-------------------------------------------------- | :------------------------------------------------------------ | :------------------------------------------------------------------------------------------------ | +| `:KittyScrollbackGenerateKittens [generate_modes]` | `generate_kittens(table)?` | Generate Kitten commands used as reference for configuring `kitty.conf` | +| `:KittyScrollbackCheckHealth` | `checkhealth()` | Run `:checkhealth kitty-scrollback` in the context of Kitty | +| `:KittyScrollbackGenerateCommandLineEditing` | `generate_command_line_editing(string\|'bash'\|'fish'\|'zsh)` | Generate command-line editing commands used as reference for configuring `bash`, `fish`, or `zsh` | ## ⌨️ Keymaps The API is available via the `kitty-scrollback.api` module. e.g., `require('kitty-scrollback.api')` @@ -857,6 +878,167 @@ The API is available via the `kitty-scrollback.api` module. e.g., `require('kitt ## πŸͺ› Optional Setup +### Command-line editing + +> [!NOTE] +> Command-line editing is only supported for `bash`, `fish`, or `zsh` +> +> Only `zsh` version 5.9 or greater is supported by kitty-scrollback.nvim for command-line editing. If you are using `zsh`, +> please confirm you have a compatible version by running `zsh --version` + +Generate the configuration and add it to the appropriate location. The comments in the configuration will provide +additional setup instructions. `KittyScrollbackGenerateCommandLineEditing` requires one parameter, either `bash`, `fish`, or `zsh`. + ```sh + nvim --headless +'KittyScrollbackGenerateCommandLineEditing ' # replace with bash, fish, or zsh + ``` + +The generated configuration will mention the environment variable `KITTY_SCROLLBACK_NVIM_EDIT_ARGS`. This can be used to pass arguments to kitty-scrollback.nvim in command-line editing mode. +This allows [Kitten Arguments](#kitten-arguments) setup specific to opening kitty-scrollback.nvim in command-line editing mode +that you may want to configure differently than your standard kitty-scrollback.nvim setup. + +### Example setups +
+bash + +- Run `nvim --headless +'KittyScrollbackGenerateCommandLineEditing bash'`. You should see similar output to the following: + +```bash + +# add the following environment variables to your bash config (e.g., ~/.bashrc) +# the editor defined in KITTY_SCROLLBACK_VISUAL will be used in place of VISUAL +# for other scenarios that are not editing the command-line. For example, C-xC-e +# will edit the current command-line in kitty-scrollback.nvim and pressing v in +# less will open the file in $KITTY_SCROLLBACK_VISUAL (defaults to nvim if not +# defined) +export KITTY_SCROLLBACK_VISUAL='nvim' +export VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.bash' + +# [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode +# by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS +# export KITTY_SCROLLBACK_NVIM_EDIT_ARGS='' + +# [optional] customize your readline config (e.g., ~/.inputrc) +# default mapping in vi mode +set keymap vi-command +"v": vi-edit-and-execute-command + +# default mapping in emacs mode +set keymap emacs +"\C-x\C-e": edit-and-execute-command +``` +- In this case, I will use the default mappings and not make any changes to `~/.inputrc`. Open, +`~/.bashrc` and add the following: +```bash +# ~/.bashrc +export VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.bash' +``` +- Close and reopen your `bash` shell +- Enter a command and press ``, you should now be editing your command line with kitty-scrollback.nvim! + +Since this configuration is making use of the `VISUAL` environment variable. The environment variable `KITTY_SCROLLBACK_VISUAL` +can be used for cases where programs open `VISUAL` that do not involve command-line editing. By default, if `KITTY_SCROLLBACK_VISUAL` +is not set, it will default to `nvim`. For example, if you open a file with `less` and press `v` to open the file with the `VISUAL` +editor, it will open in the command defined in `KITTY_SCROLLBACK_VISUAL`. So, in this case open in `nvim` as you typically would expect. + +
+
+fish + +- Run `nvim --headless +'KittyScrollbackGenerateCommandLineEditing fish'`. You should see similar output to the following: + +```fish +# add the following function and bindings to your fish config +# e.g., ~/.config/fish/conf.d/kitty_scrollback_nvim.fish or ~/.config/fish/config.fish + +function kitty_scrollback_edit_command_buffer + set --local --export VISUAL '~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + edit_command_buffer + commandline '' +end + +bind --mode default \ee kitty_scrollback_edit_command_buffer +bind --mode default \ev kitty_scrollback_edit_command_buffer + +bind --mode visual \ee kitty_scrollback_edit_command_buffer +bind --mode visual \ev kitty_scrollback_edit_command_buffer + +bind --mode insert \ee kitty_scrollback_edit_command_buffer +bind --mode insert \ev kitty_scrollback_edit_command_buffer + +# [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode +# by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS +# set --global --export KITTY_SCROLLBACK_NVIM_EDIT_ARGS '' +``` + +- In this case, I will map `` to use kitty-scrollback.nvim and keep `` with the default mappings. Open +`~/.config/fish/conf.d/kitty_scrollback_nvim.fish` and add the following: + +```fish +# ~/.config/fish/conf.d/kitty_scrollback_nvim.fish +function kitty_scrollback_edit_command_buffer + set --local --export VISUAL '~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + edit_command_buffer + commandline '' +end + +bind --mode default \ee kitty_scrollback_edit_command_buffer +bind --mode visual \ee kitty_scrollback_edit_command_buffer +bind --mode insert \ee kitty_scrollback_edit_command_buffer +``` +- Close and reopen your `fish` shell +- Enter a command and press `` (where `M` is the alt key), you should now be editing your command line with kitty-scrollback.nvim! + +Since this example configuration is not rebinding `\ev`. You can still press `` (where `M` is the alt key), to open then +command-line buffer in the editor defined in the `VISUAL` environment variable. This gives you some extra flexibility in the fish shell! + +
+
+zsh + +- Run `nvim --headless +'KittyScrollbackGenerateCommandLineEditing zsh'`. You should see similar output to the following: + +```zsh +# IMPORTANT: kitty-scrollback.nvim only supports zsh 5.9 or greater for command-line editing, +# please check your version by running: zsh --version + +# add the following environment variables to your zsh config (e.g., ~/.zshrc) + +autoload -Uz edit-command-line +zle -N edit-command-line + +function kitty_scrollback_edit_command_line() { + local VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + zle edit-command-line + zle kill-whole-line +} +zle -N kitty_scrollback_edit_command_line + +bindkey '^x^e' kitty_scrollback_edit_command_line + +# [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode +# by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS +# export KITTY_SCROLLBACK_NVIM_EDIT_ARGS='' +``` +- Open `~/.zshrc` and add the following: +```zsh +# ~/.zshrc +autoload -Uz edit-command-line +zle -N edit-command-line + +function kitty_scrollback_edit_command_line() { + local VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + zle edit-command-line + zle kill-whole-line +} +zle -N kitty_scrollback_edit_command_line + +bindkey '^x^e' kitty_scrollback_edit_command_line +``` +- Close and reopen your `zsh` shell +- Enter a command and press ``, you should now be editing your command line with kitty-scrollback.nvim! + +
+ ### tmux (πŸ§ͺ experimental ) > [!WARNING]\ diff --git a/doc/kitty-scrollback.nvim.txt b/doc/kitty-scrollback.nvim.txt index eb9350fa..6cb49999 100644 --- a/doc/kitty-scrollback.nvim.txt +++ b/doc/kitty-scrollback.nvim.txt @@ -88,8 +88,27 @@ FEATURES *kitty-scrollback.nvim-features* - `kitty-scrollback.nvim` automatically closes and executes the content of the paste window +`-` `😹 Edit the current command line (bash, fish, or zsh)` + + +https://github.com/user-attachments/assets/6b4f177f-34c2-4ce7-9adb-15e0d3e19498 + +This requires extra steps to setup. See optional +|kitty-scrollback.nvim-command-line-editing-setup|. + +- Start typing a command in your shell +- Open the current command line in kitty-scrollback.nvim with the following keybind + - bash: `` + - fish: `` or `` (where `M` is the alt key) + - zsh: `` +- Modify the command and do any additional operations that you typically would perform in kitty-scrollback.nvim + + `-` `😾 tmux support (πŸ§ͺ experimental )` +This requires extra steps to setup. See optional +|kitty-scrollback.nvim-tmux-setup|. + - Open a tmux pane’s scrollback history (default mapping `[`) - That’s it! You are in Neovim, navigate the scrollback buffer. @@ -166,7 +185,7 @@ INSTALLATION *kitty-scrollback.nvim-installation* 'mikesmithgh/kitty-scrollback.nvim', enabled = true, lazy = true, - cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' }, + cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing' }, event = { 'User KittyScrollbackLaunch' }, -- version = '*', -- latest stable version, may have breaking changes if major version changed -- version = '^6.0.0', -- pin major version, include fixes and features that do not have breaking changes @@ -184,7 +203,7 @@ INSTALLATION *kitty-scrollback.nvim-installation* 'mikesmithgh/kitty-scrollback.nvim', disable = false, opt = true, - cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' }, + cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing' }, event = { 'User KittyScrollbackLaunch' }, -- tag = '*', -- latest stable version, may have breaking changes if major version changed -- tag = 'v6.0.0', -- pin specific tag @@ -768,7 +787,7 @@ example, I will create the directory `~/.config/ksb-nvim` and add the file "mikesmithgh/kitty-scrollback.nvim", enabled = true, lazy = true, - cmd = { "KittyScrollbackGenerateKittens", "KittyScrollbackCheckHealth" }, + cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing' }, event = { "User KittyScrollbackLaunch" }, config = function() require("kitty-scrollback").setup({ @@ -801,8 +820,11 @@ should look like in your kitty.conf. ENVIRONMENT VARIABLES *kitty-scrollback.nvim-environment-variables* -The environment variable `KITTY_SCROLLBACK_NVIM` is set to `true` while -kitty-scrollback.nvim is active. +The environment variable `KITTY_SCROLLBACK_NVIM` is set to `'true'` while +kitty-scrollback.nvim is active. > `β„Ή` `NOTE` > > `'true'` is a string because +`KITTY_SCROLLBACK_NVIM` is an environment variable. Make sure to use a string +`'true'` in Lua > instead of accidentally using a boolean `true`. Otherwise, +the conditional checks will not operate as expected. This can be used to in your Neovim configuration to provide kitty-scrollback.nvim specific behavior that may differ from a regular Neovim @@ -858,17 +880,21 @@ COMMANDS *kitty-scrollback.nvim-commands* The API is available via the `kitty-scrollback.api` module. e.g., `require('kitty-scrollback.api')` - ----------------------------------------------------------------------------------------------------------------------------------------- - Command API Description - -------------------------------------------------- ------------------------------------------------------ ------------------------------- - :KittyScrollbackGenerateKittens [generate_modes] generate_kittens(table)? Generate Kitten commands used - as reference for configuring - kitty.conf + ------------------------------------------------------------------------------------------------------------------------------------------------- + Command API Description + -------------------------------------------------- ------------------------------------------------------------- -------------------------------- + :KittyScrollbackGenerateKittens [generate_modes] generate_kittens(table)? Generate Kitten commands used as + reference for configuring + kitty.conf - :KittyScrollbackCheckHealth checkhealth() Run - :checkhealth kitty-scrollback - in the context of Kitty - ----------------------------------------------------------------------------------------------------------------------------------------- + :KittyScrollbackCheckHealth checkhealth() Run + :checkhealth kitty-scrollback in + the context of Kitty + + :KittyScrollbackGenerateCommandLineEditing generate_command_line_editing(string\|'bash'\|'fish'\|'zsh) Generate command-line editing + commands used as reference for + configuring bash, fish, or zsh + ------------------------------------------------------------------------------------------------------------------------------------------------- KEYMAPS *kitty-scrollback.nvim-keymaps* @@ -914,6 +940,182 @@ The API is available via the `kitty-scrollback.api` module. e.g., OPTIONAL SETUP *kitty-scrollback.nvim-optional-setup* +COMMAND-LINE EDITING ~ + + + `β„Ή` `NOTE` + Command-line editing is only supported for `bash`, `fish`, or `zsh` + Only `zsh` version 5.9 or greater is supported by kitty-scrollback.nvim for + command-line editing. If you are using `zsh`, please confirm you have a + compatible version by running `zsh --version` +Generate the configuration and add it to the appropriate location. The comments +in the configuration will provide additional setup instructions. +`KittyScrollbackGenerateCommandLineEditing` requires one parameter, either +`bash`, `fish`, or `zsh`. `sh nvim --headless ++'KittyScrollbackGenerateCommandLineEditing ' # replace with +bash, fish, or zsh` + +The generated configuration will mention the environment variable +`KITTY_SCROLLBACK_NVIM_EDIT_ARGS`. This can be used to pass arguments to +kitty-scrollback.nvim in command-line editing mode. This allows +|kitty-scrollback.nvim-kitten-arguments| setup specific to opening +kitty-scrollback.nvim in command-line editing mode that you may want to +configure differently than your standard kitty-scrollback.nvim setup. + + +EXAMPLE SETUPS ~ + + +`-` `bash` +- Run `nvim --headless +'KittyScrollbackGenerateCommandLineEditing bash'`. You + should see similar output to the following: + +>bash + + # add the following environment variables to your bash config (e.g., ~/.bashrc) + # the editor defined in KITTY_SCROLLBACK_VISUAL will be used in place of VISUAL + # for other scenarios that are not editing the command-line. For example, C-xC-e + # will edit the current command-line in kitty-scrollback.nvim and pressing v in + # less will open the file in $KITTY_SCROLLBACK_VISUAL (defaults to nvim if not + # defined) + export KITTY_SCROLLBACK_VISUAL='nvim' + export VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.bash' + + # [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode + # by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS + # export KITTY_SCROLLBACK_NVIM_EDIT_ARGS='' + + # [optional] customize your readline config (e.g., ~/.inputrc) + # default mapping in vi mode + set keymap vi-command + "v": vi-edit-and-execute-command + + # default mapping in emacs mode + set keymap emacs + "\C-x\C-e": edit-and-execute-command +< + +- In this case, I will use the default mappings and not make any changes to `~/.inputrc`. Open, + `~/.bashrc` and add the following: + +>bash + # ~/.bashrc + export VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.bash' +< + +- Close and reopen your `bash` shell +- Enter a command and press ``, you should now be editing your command line with kitty-scrollback.nvim! + +Since this configuration is making use of the `VISUAL` environment variable. +The environment variable `KITTY_SCROLLBACK_VISUAL` can be used for cases where +programs open `VISUAL` that do not involve command-line editing. By default, if +`KITTY_SCROLLBACK_VISUAL` is not set, it will default to `nvim`. For example, +if you open a file with `less` and press `v` to open the file with the `VISUAL` +editor, it will open in the command defined in `KITTY_SCROLLBACK_VISUAL`. So, +in this case open in `nvim` as you typically would expect. + + +`-` `fish` +- Run `nvim --headless +'KittyScrollbackGenerateCommandLineEditing fish'`. You + should see similar output to the following: + +>fish + # add the following function and bindings to your fish config + # e.g., ~/.config/fish/conf.d/kitty_scrollback_nvim.fish or ~/.config/fish/config.fish + + function kitty_scrollback_edit_command_buffer + set --local --export VISUAL '~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + edit_command_buffer + commandline '' + end + + bind --mode default \ee kitty_scrollback_edit_command_buffer + bind --mode default \ev kitty_scrollback_edit_command_buffer + + bind --mode visual \ee kitty_scrollback_edit_command_buffer + bind --mode visual \ev kitty_scrollback_edit_command_buffer + + bind --mode insert \ee kitty_scrollback_edit_command_buffer + bind --mode insert \ev kitty_scrollback_edit_command_buffer + + # [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode + # by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS + # set --global --export KITTY_SCROLLBACK_NVIM_EDIT_ARGS '' +< + +- In this case, I will map `` to use kitty-scrollback.nvim and keep `` with the default mappings. Open + `~/.config/fish/conf.d/kitty_scrollback_nvim.fish` and add the following: + +>fish + # ~/.config/fish/conf.d/kitty_scrollback_nvim.fish + function kitty_scrollback_edit_command_buffer + set --local --export VISUAL '~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + edit_command_buffer + commandline '' + end + + bind --mode default \ee kitty_scrollback_edit_command_buffer + bind --mode visual \ee kitty_scrollback_edit_command_buffer + bind --mode insert \ee kitty_scrollback_edit_command_buffer +< + +- Close and reopen your `fish` shell +- Enter a command and press `` (where `M` is the alt key), you should now be editing your command line with kitty-scrollback.nvim! + +Since this example configuration is not rebinding `\ev`. You can still press +`` (where `M` is the alt key), to open then command-line buffer in the +editor defined in the `VISUAL` environment variable. This gives you some extra +flexibility in the fish shell! + + +`-` `zsh` +- Run `nvim --headless +'KittyScrollbackGenerateCommandLineEditing zsh'`. You + should see similar output to the following: + +>zsh + # IMPORTANT: kitty-scrollback.nvim only supports zsh 5.9 or greater for command-line editing, + # please check your version by running: zsh --version + + # add the following environment variables to your zsh config (e.g., ~/.zshrc) + + autoload -Uz edit-command-line + zle -N edit-command-line + + function kitty_scrollback_edit_command_line() { + local VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + zle edit-command-line + zle kill-whole-line + } + zle -N kitty_scrollback_edit_command_line + + bindkey '^x^e' kitty_scrollback_edit_command_line + + # [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode + # by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS + # export KITTY_SCROLLBACK_NVIM_EDIT_ARGS='' +< + +- Open `~/.zshrc` and add the following: + +>zsh + # ~/.zshrc + autoload -Uz edit-command-line + zle -N edit-command-line + + function kitty_scrollback_edit_command_line() { + local VISUAL='~/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh' + zle edit-command-line + zle kill-whole-line + } + zle -N kitty_scrollback_edit_command_line + + bindkey '^x^e' kitty_scrollback_edit_command_line +< + +- Close and reopen your `zsh` shell +- Enter a command and press ``, you should now be editing your command line with kitty-scrollback.nvim! + + TMUX ( EXPERIMENTAL ) ~ diff --git a/doc/kitty-scrollback.nvim_spec.txt b/doc/kitty-scrollback.nvim_spec.txt index c1cc2062..cb4513da 100644 --- a/doc/kitty-scrollback.nvim_spec.txt +++ b/doc/kitty-scrollback.nvim_spec.txt @@ -247,6 +247,10 @@ KsbGenKittenModes *kitty-scrollback.api.KsbGenKittenModes* M.generate_kittens() *kitty-scrollback.api.generate_kittens* + *kitty-scrollback.api.generate_command_line_editing* +M.generate_command_line_editing() + + M.checkhealth() *kitty-scrollback.api.checkhealth* diff --git a/lua/kitty-scrollback/api.lua b/lua/kitty-scrollback/api.lua index 4b8e7e63..7a7f4960 100644 --- a/lua/kitty-scrollback/api.lua +++ b/lua/kitty-scrollback/api.lua @@ -163,6 +163,111 @@ M.generate_kittens = function(generate_modes) end end +M.generate_command_line_editing = function(shell) + shell = (shell and next(shell)) and shell[1] or 'undefined' + local kitty_scrollback_edit_command_line = vim.fn.fnamemodify( + vim.api.nvim_get_runtime_file('scripts/edit_command_line.sh', false)[1], + ':p' + ) + local kitty_scrollback_edit_command_line_bash = vim.fn.fnamemodify( + vim.api.nvim_get_runtime_file('scripts/edit_command_line.bash', false)[1], + ':p' + ) + + local configs = { + bash = { + [[# add the following environment variables to your bash config (e.g., ~/.bashrc)]], + [[# the editor defined in KITTY_SCROLLBACK_VISUAL will be used in place of VISUAL]], + [[# for other scenarios that are not editing the command-line. For example, C-xC-e]], + [[# will edit the current command-line in kitty-scrollback.nvim and pressing v in]], + [[# less will open the file in $KITTY_SCROLLBACK_VISUAL (defaults to nvim if not]], + [[# defined)]], + [[export KITTY_SCROLLBACK_VISUAL='nvim']], + [[export VISUAL=']] .. kitty_scrollback_edit_command_line_bash .. [[']], + [[# [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode]], + [[# by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS]], + [[# export KITTY_SCROLLBACK_NVIM_EDIT_ARGS='']], + [[]], + [[# [optional] customize your readline config (e.g., ~/.inputrc) ]], + [[# default mapping in vi mode]], + [[set keymap vi-command]], + [["v": vi-edit-and-execute-command]], + [[]], + [[# default mapping in emacs mode]], + [[set keymap emacs]], + [["\C-x\C-e": edit-and-execute-command]], + [[]], + }, + fish = { + [[# add the following function and bindings to your fish config]], + [[# e.g., ~/.config/fish/conf.d/kitty_scrollback_nvim.fish or ~/.config/fish/config.fish]], + [[]], + [[function kitty_scrollback_edit_command_buffer]], + [[ set --local --export VISUAL ']] .. kitty_scrollback_edit_command_line .. [[']], + [[ edit_command_buffer]], + [[ commandline '']], + [[end]], + [[]], + [[bind --mode default \ee kitty_scrollback_edit_command_buffer]], + [[bind --mode default \ev kitty_scrollback_edit_command_buffer]], + [[]], + [[bind --mode visual \ee kitty_scrollback_edit_command_buffer]], + [[bind --mode visual \ev kitty_scrollback_edit_command_buffer]], + [[]], + [[bind --mode insert \ee kitty_scrollback_edit_command_buffer]], + [[bind --mode insert \ev kitty_scrollback_edit_command_buffer]], + [[]], + [[# [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode]], + [[# by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS]], + [[# set --global --export KITTY_SCROLLBACK_NVIM_EDIT_ARGS '']], + [[]], + }, + zsh = { + [[# IMPORTANT: kitty-scrollback.nvim only supports zsh 5.9 or greater for command-line editing,]], + [[# please check your version by running: zsh --version]], + [[]], + [[# add the following environment variables to your zsh config (e.g., ~/.zshrc)]], + [[]], + [[autoload -Uz edit-command-line]], + [[zle -N edit-command-line]], + [[]], + [[function kitty_scrollback_edit_command_line() { ]], + [[ local VISUAL=']] .. kitty_scrollback_edit_command_line .. [[']], + [[ zle edit-command-line]], + [[ zle kill-whole-line]], + [[}]], + [[zle -N kitty_scrollback_edit_command_line]], + [[]], + [[bindkey '^x^e' kitty_scrollback_edit_command_line]], + [[]], + [[# [optional] pass arguments to kitty-scrollback.nvim in command-line editing mode]], + [[# by using the environment variable KITTY_SCROLLBACK_NVIM_EDIT_ARGS]], + [[# export KITTY_SCROLLBACK_NVIM_EDIT_ARGS='']], + [[]], + }, + } + + ---@type table|string + local config = configs[shell] + if not config then + config = 'no config found for: ' .. shell + end + + local bufid = vim.api.nvim_create_buf(true, true) + vim.api.nvim_set_option_value('filetype', shell or '', { + buf = bufid, + }) + vim.api.nvim_set_current_buf(bufid) + vim.api.nvim_buf_set_lines(bufid, 0, -1, false, config) + + if #vim.api.nvim_list_uis() == 0 then -- if nvim is running in headless mode + for _, line in pairs(config) do + vim.print(line) + end + M.quit_all() + end +end + M.checkhealth = function() local kitty_scrollback_kitten = vim.fn.fnamemodify( vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1], diff --git a/lua/kitty-scrollback/init.lua b/lua/kitty-scrollback/init.lua index 41d88901..9b1cea2a 100644 --- a/lua/kitty-scrollback/init.lua +++ b/lua/kitty-scrollback/init.lua @@ -39,6 +39,21 @@ M.setup = function(configs) once = true, callback = function() end, }) + + ---@brief [[ + ---:'KittyScrollbackGenerateCommandLineEditing' Generate commands used as reference for command-line editing + --- + --- See: ~ + --- |kitty.api.generate_edit_commands| + ---@brief ]] + vim.api.nvim_create_user_command('KittyScrollbackGenerateCommandLineEditing', function(o) + require('kitty-scrollback.api').generate_command_line_editing(o.fargs) + end, { + nargs = 1, + complete = function() + return { 'bash', 'fish', 'zsh' } + end, + }) end return M diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index e353abfe..a5236f2f 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -428,6 +428,22 @@ M.launch = function() opts.callbacks.after_ready(p.kitty_data, opts) end) end + if ksb_util.command_line_editing_mode then + vim.schedule(function() + local input = ksb_util.command_line_editing_mode_input + if input == nil or input == '' then + vim.notify( + 'kitty-scrollback.nvim: no input file found in environment variable KITTY_SCROLLBACK_NVIM_EDIT_INPUT', + vim.log.levels.ERROR, + {} + ) + else + local input_lines = vim.fn.readfile(input) + ksb_win.open_paste_window(#input_lines == 1 and input_lines[1] == '') + vim.api.nvim_buf_set_lines(p.paste_bufid, 0, -1, false, input_lines) + end + end) + end ksb_api.close_kitty_loading_window() if block_input_timer then vim.fn.timer_stop(block_input_timer) diff --git a/lua/kitty-scrollback/util.lua b/lua/kitty-scrollback/util.lua index 64c83b82..31a77eaa 100644 --- a/lua/kitty-scrollback/util.lua +++ b/lua/kitty-scrollback/util.lua @@ -216,4 +216,7 @@ M.system_handle_error = function(cmd, error_header, sys_opts, ignore_error) return ok, result end +M.command_line_editing_mode = vim.env.KITTY_SCROLLBACK_NVIM_MODE == 'command_line_editing' +M.command_line_editing_mode_input = vim.env.KITTY_SCROLLBACK_NVIM_EDIT_INPUT + return M diff --git a/lua/kitty-scrollback/windows.lua b/lua/kitty-scrollback/windows.lua index a5c43e16..27c5e648 100644 --- a/lua/kitty-scrollback/windows.lua +++ b/lua/kitty-scrollback/windows.lua @@ -71,8 +71,15 @@ end M.open_paste_window = function(start_insert) vim.cmd.stopinsert() + if ksb_util.command_line_editing_mode then + p.pos = nil + end + if not p.pos then - if opts.kitty_get_text.extent == 'screen' or opts.kitty_get_text.extent == 'all' then + if + (opts.kitty_get_text.extent == 'screen' or opts.kitty_get_text.extent == 'all') + and not ksb_util.command_line_editing_mode + then vim.notify( 'kitty-scrollback.nvim: missing position with extent=' .. opts.kitty_get_text.extent, vim.log.levels.WARN, diff --git a/scripts/edit_command_line.bash b/scripts/edit_command_line.bash new file mode 100755 index 00000000..1ca78e5b --- /dev/null +++ b/scripts/edit_command_line.bash @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +if [[ "$1" == *bash-fc* ]]; then + script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + "$script_dir/edit_command_line.sh" "$@" +else + "${KITTY_SCROLLBACK_VISUAL:-nvim}" "$@" +fi diff --git a/scripts/edit_command_line.sh b/scripts/edit_command_line.sh new file mode 100755 index 00000000..1d96fcc0 --- /dev/null +++ b/scripts/edit_command_line.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +if [ -z "$1" ]; then + printf 'missing input file\n' + exit 2 +fi + +# set input_file to the last argument +# the last argument is used because in the case of zsh, commands maybe be passed before the filename e.g., (-c) +for input_file; do true; done + +case "$input_file" in +*.fish) + shell_type="fish" + ;; +*.zsh) + shell_type="zsh" + ;; +*) + shell_type="bash" + ;; +esac + +# after exiting this script and before it has been read by kitty-scrollback.nvim +# the contents of the original input_file may be altered +# avoid this by copying the input_file to a new file that will be referenced +ksb_input_dir=$(mktemp -d) +ksb_input_file="$ksb_input_dir/input.ksb_editcommand" +cp "$input_file" "$ksb_input_file" + +script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) +ksb_dir=$(dirname "$script_dir") +# shellcheck disable=SC2086 +kitty @ kitten "$ksb_dir/python/kitty_scrollback_nvim.py" --env "KITTY_SCROLLBACK_NVIM_MODE=command_line_editing" --env "KITTY_SCROLLBACK_NVIM_EDIT_INPUT=$ksb_input_file" $KITTY_SCROLLBACK_NVIM_EDIT_ARGS + +# small delay before to avoid adding an extra prompt after +# this command has exited and before kitty-scrollback.nvim +# has had time to get the scrollback buffer from kitty +sleep 1 + +if [ "$shell_type" = "bash" ]; then + # exit non-zero so that the command is not executed in bash + exit 1 +fi diff --git a/scripts/internal/__generate_vimdocs.sh b/scripts/internal/__generate_vimdocs.sh index 822d87ca..45210cd4 100755 --- a/scripts/internal/__generate_vimdocs.sh +++ b/scripts/internal/__generate_vimdocs.sh @@ -7,31 +7,31 @@ mkdir -p tmp_vimdoc_workdir cp README.md tmp_vimdoc_workdir/README.md # shellcheck disable=SC2016 sed -E -e's/\[!(NOTE|WARNING|IMPORTANT)\].*/[!\1]\n>/Ig' -e 's/.*(.+)<\/summary>/- VIMDOC_SUMMARY_HEADER `\1`\n/g' \ - -e 's/(.+)<\/a>/\2 <\1>/g' tmp_vimdoc_workdir/README.md + -e 's/(.+)<\/a>/\2 <\1>/g' tmp_vimdoc_workdir/README.md # panvimdoc ~/gitrepos/panvimdoc/panvimdoc.sh \ - --description 'For NVIM v0.9+' \ - --project-name kitty-scrollback.nvim \ - --input-file tmp_vimdoc_workdir/README.md \ - --demojify true \ - --toc true \ - --dedup-subheadings false \ - --treesitter true + --description 'For NVIM v0.9+' \ + --project-name kitty-scrollback.nvim \ + --input-file tmp_vimdoc_workdir/README.md \ + --demojify true \ + --toc true \ + --dedup-subheadings false \ + --treesitter true # postformat kitty-scrollback.nvim.txt cp doc/kitty-scrollback.nvim.txt tmp_vimdoc_workdir/kitty-scrollback.nvim.txt # shellcheck disable=SC2016 sed -E \ - -e 's/\[!(IMPORTANT)\]/|β€Ό| |\1|/Ig' \ - -e 's/\[!(NOTE)\]/`β„Ή` `\1` /Ig' \ - -e 's/\[!(WARNING)\]/*⚠* *\1* /Ig' \ - -e 's/^- VIMDOC_SUMMARY_HEADER(.*)/\n`-`\1/g' \ - -e 's/^[[:space:]]+(>.*)/\n\1/g' \ - -e 's/^[[:space:]]+(<.*)/\1/g' \ - doc/kitty-scrollback.nvim.txt + -e 's/\[!(IMPORTANT)\]/|β€Ό| |\1|/Ig' \ + -e 's/\[!(NOTE)\]/`β„Ή` `\1` /Ig' \ + -e 's/\[!(WARNING)\]/*⚠* *\1* /Ig' \ + -e 's/^- VIMDOC_SUMMARY_HEADER(.*)/\n`-`\1/g' \ + -e 's/^[[:space:]]+(>.*)/\n\1/g' \ + -e 's/^[[:space:]]+(<.*)/\1/g' \ + doc/kitty-scrollback.nvim.txt # cleanup preformat README.md rm -rf tmp_vimdoc_workdir diff --git a/scripts/internal/__update_branch_protection_rules.sh b/scripts/internal/__update_branch_protection_rules.sh index 93ace0e8..169ee883 100755 --- a/scripts/internal/__update_branch_protection_rules.sh +++ b/scripts/internal/__update_branch_protection_rules.sh @@ -3,5 +3,4 @@ # update branch protection rules via the github API # the test matrix can get complex, this offers a convenient way to update the branch protection rules instead of clicking # each individual action in the UI -gh api /repos/mikesmithgh/kitty-scrollback.nvim/branches/main/protection --method PUT --input __branch-protection-rules.json - +gh api /repos/mikesmithgh/kitty-scrollback.nvim/branches/main/protection --method PUT --input __branch-protection-rules.json diff --git a/scripts/mini.sh b/scripts/mini.sh index 60e8af23..96674b97 100755 --- a/scripts/mini.sh +++ b/scripts/mini.sh @@ -11,8 +11,8 @@ trap 'echo "EXIT detected with exit status $?"' EXIT # OS temp dir & script working dir TEMPDIR=$(dirname "$(mktemp -u)") BASEDIR=$( - cd "$(dirname "$0")" - pwd -P + cd "$(dirname "$0")" + pwd -P ) nvim_bin=${NVIM:-nvim} @@ -23,36 +23,36 @@ tmp_rtp="${tmp_dir}/nvim/site/pack/vendor/start" packpath="${tmp_dir}/nvim/site" usage() { - echo "Usage $0" + echo "Usage $0" } if [ "${1:-}" = "reset" ]; then - rm -rf "${tmp_dir}" + rm -rf "${tmp_dir}" fi download_plugin() { - repo="https://github.com/${1}/${2}" - folder="${tmp_rtp}/${2}" - if [ "${1:-}" = "reset" ]; then - rm -rf "${folder}" - fi - if [ ! -d "$folder" ]; then - printf "Downloading %s into %s..." "${repo}" "${folder}" - git clone --depth 1 "${repo}" "${folder}" - else - echo "Updating '${repo}' in ${folder}..." - git -C "${folder}" pull --rebase - fi + repo="https://github.com/${1}/${2}" + folder="${tmp_rtp}/${2}" + if [ "${1:-}" = "reset" ]; then + rm -rf "${folder}" + fi + if [ ! -d "$folder" ]; then + printf "Downloading %s into %s..." "${repo}" "${folder}" + git clone --depth 1 "${repo}" "${folder}" + else + echo "Updating '${repo}' in ${folder}..." + git -C "${folder}" pull --rebase + fi } mkdir -p "$tmp_rtp" # if exists, link to local folder so we can test local changes if [ -d "${plug_dir}" ]; then - echo "Using local plugin ${plug_name} from '${plug_dir}'" - ln -fs "${plug_dir}" "${tmp_rtp}" + echo "Using local plugin ${plug_name} from '${plug_dir}'" + ln -fs "${plug_dir}" "${tmp_rtp}" else - download_plugin "mikesmithgh" "$plug_name" + download_plugin "mikesmithgh" "$plug_name" fi tmp_plug_dir="${tmp_rtp}/${plug_name}" @@ -61,11 +61,11 @@ printf "\n\t\033[38;2;167;192;128mctrl-c to quit\033[0m\n" # run kitty kitty --config="${tmp_rtp}/${plug_name}/scripts/kitty.conf" \ - --override "action_alias=kitty_scrollback_nvim kitten ${tmp_plug_dir}/python/kitty_scrollback_nvim.py --env HOME=${TEMPDIR} --env PACKPATH=${packpath} --nvim-args -u ${tmp_plug_dir}/scripts/init.lua" \ - --override "map kitty_mod+h kitty_scrollback_nvim" \ - --override "map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output" \ - --override "mouse_map ctrl+shift+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_visited_cmd_output" \ - kitten @ launch --cwd="${tmp_dir}" --hold printf "\n\t \033[0m\033[38;2;167;192;128mkitty-scrollback.nvim\033[0m \033[38;2;150;140;129mmini.sh \033[0m\n\t\033[38;2;150;140;129mπŸ­½β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”πŸ­Ύ\033[0m\033[38;2;150;140;129m\n\t\033[38;2;150;140;129m▏\033[0m\033[38;2;167;192;128mkitty_mod+h\033[0m \033[38;2;150;140;129mscrollback buffer β–•\033[0m\n\t\033[38;2;150;140;129m▏\033[0m\033[38;2;167;192;128mkitty_mod+g \033[0m \033[38;2;150;140;129mlast command output β–•\033[0m\n\t\033[38;2;150;140;129m▏\033[0m\033[38;2;167;192;128mctrl+shift+right-click\033[0m \033[38;2;150;140;129mselected command outputβ–•\033[0m\n\t\033[38;2;150;140;129mπŸ­Όβ–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–πŸ­Ώ\033[0m\n" + --override "action_alias=kitty_scrollback_nvim kitten ${tmp_plug_dir}/python/kitty_scrollback_nvim.py --env HOME=${TEMPDIR} --env PACKPATH=${packpath} --nvim-args -u ${tmp_plug_dir}/scripts/init.lua" \ + --override "map kitty_mod+h kitty_scrollback_nvim" \ + --override "map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output" \ + --override "mouse_map ctrl+shift+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_visited_cmd_output" \ + kitten @ launch --cwd="${tmp_dir}" --hold printf "\n\t \033[0m\033[38;2;167;192;128mkitty-scrollback.nvim\033[0m \033[38;2;150;140;129mmini.sh \033[0m\n\t\033[38;2;150;140;129mπŸ­½β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”β–”πŸ­Ύ\033[0m\033[38;2;150;140;129m\n\t\033[38;2;150;140;129m▏\033[0m\033[38;2;167;192;128mkitty_mod+h\033[0m \033[38;2;150;140;129mscrollback buffer β–•\033[0m\n\t\033[38;2;150;140;129m▏\033[0m\033[38;2;167;192;128mkitty_mod+g \033[0m \033[38;2;150;140;129mlast command output β–•\033[0m\n\t\033[38;2;150;140;129m▏\033[0m\033[38;2;167;192;128mctrl+shift+right-click\033[0m \033[38;2;150;140;129mselected command outputβ–•\033[0m\n\t\033[38;2;150;140;129mπŸ­Όβ–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–πŸ­Ώ\033[0m\n" cat <