Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make the current cmdline editable in place #245

Closed
IndianBoy42 opened this issue May 15, 2024 · 8 comments · Fixed by #253
Closed

feat: make the current cmdline editable in place #245

IndianBoy42 opened this issue May 15, 2024 · 8 comments · Fixed by #253
Labels
enhancement New feature or request released

Comments

@IndianBoy42
Copy link

Sometimes I start typing a long complicated command and then I get annoyed with the lack of vim keybindings. My shell (fish) has a keybinding to open the current commandline in $EDITOR but then I lose sight of the scrollback, so its suboptimal.

kitty-scrollback.nvim has the potential to be useful here. Currently adding to the current commandline is easy, but there is no easy way to select, edit or replace the existing commandline.

@mikesmithgh mikesmithgh changed the title Make the current cmdline editable in place feat: make the current cmdline editable in place May 15, 2024
@mikesmithgh mikesmithgh added the enhancement New feature or request label May 15, 2024
@mikesmithgh
Copy link
Owner

Hi @IndianBoy42, I think this is a good idea.

What binding are you using to do this in fish?

I am currently doing the same thing for but with bash edit-and-execute-command (C-x C-e).

I need to figure out if there is a way to grab the current command in a shell agnostic way (or maybe just support bash, zsh, fish). Kitty may have something around this related to shell integration, I'll take a look.

@IndianBoy42
Copy link
Author

IndianBoy42 commented May 16, 2024 via email

@mikesmithgh
Copy link
Owner

In first it's Alt+e Shell agnostic is ideal, but if not then covering bash zsh and fish should cover 99% of users.

Thanks! Looks like zsh doesn't have a default binding but does offer it as well.

https://unix.stackexchange.com/questions/6620/how-to-edit-command-line-in-full-screen-editor-in-zsh

autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line

I'll have to think about the implementation of this a bit, but can hopefully come up with something 👍

@IndianBoy42
Copy link
Author

After checking it out a bit I think direct shell integration is necessary. OSC133 doesn't mark the cmdline editable area.

The user modifies the edit command binding so that it is something like EDITOR=kitty-scrollback-editor edit-command-line. From the scrollback overlay we send the keys to the underlying window, which doesn't even open neovim it just stashes that filename somewhere for the overlay to find and blocks waiting for the overlay to close. From the scrollback overlay we use that filename to get the current commandline, find where it is in the buffer (we know its near the cursor so shouldn't be a costly search), and make just that region editable. Or make a popup. When the scrollback is closing we send the potentially updated commandline to that temporary file and unblock the underlying window.

@mikesmithgh
Copy link
Owner

Thanks! I agree, this sounds like the approach to take.

When the scrollback is closing we send the potentially updated commandline to that temporary file and unblock the underlying window.

I'm not sure how long the temporary file is available but we could also exit 1 for the EDITOR command and just use that input file as reference of the cmdline as well. Then prefill that prompt window. I think it would just need to clear the existing command before executing.

There is an after_ready callback that may make sense to hook into for this.

Maybe something like

EDITOR='kitty @ kitten /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --config ksb_builtin_edit_command_line' edit-command-line

Would need to maybe create a helper script or a way to pass the filename and then in the ksb_builtin_edit_command_line config have the callback after_ready that prefills and opens the paste window with the command.

I've been busy of late, so not sure when I'll have time to dedicate to implementing. But, I think we are going down the right track.

@mikesmithgh
Copy link
Owner

mikesmithgh commented May 31, 2024

Hey @IndianBoy42 I have a draft PR #253 for this feature that I am still working on. It is in a good state, I just need to document and write tests. If you'd like to try it out and give me feedback, use the branch feat-command-line-editing-mode.

You will have to run the command :KittyScrollbackGenerateCommandLineEditing fish and it will generate the fish config that you can use for this plugin. If you are using lazy.nvim make sure to add KittyScrollbackGenerateCommandLineEditing to the commands like:

  {
    'mikesmithgh/kitty-scrollback.nvim',
    -- ...
    cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing', },
    -- ...
  }

It will look something like this (but have updated paths for your machine):

# add the following function and bindings to your fish config (e.g., ~/.config/fish/config.fish) 

function kitty_scrollback_edit_command_buffer
  set -lx VISUAL '/Users/mike/gitrepos/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

Please let me know if it works for you or you have any issues 👍

Demo:

fish-command-line-editing.mp4

@IndianBoy42
Copy link
Author

Very cool! checking it out now.

A cool tip for fish integration is that every fish script in ~/.config/fish/conf.d/ is automatically sourced before config.fish. Thats how fish plugins are generally implemented

I'm not sure how zsh plugins work but I suspect there is somewhere you could the bindings file automatically so it Just Works TM for users

bash... 🤷

@mikesmithgh
Copy link
Owner

🎉 This issue has been resolved in version 6.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants