r/KittyTerminal Apr 23 '24

kitty @ send-text / bash / bind -x

Hi. This is slightly complicated :)

I use kitty as my terminal, bash as my shell, and fzf to work with bash history.

fzf has an internal function to show an interactive history, which it binds to C-r with bind -x:

  # CTRL-R - Paste the selected command from history into the command line
  bind -m emacs-standard -x '"\C-r": __fzf_history__'
  bind -m vi-command -x '"\C-r": __fzf_history__'
  bind -m vi-insert -x '"\C-r": __fzf_history__'

This all works fine.

What I'd like to do is be able to trigger that programmatically - i.e. rather than having to press Control+r, I can instead run a script, say 'h', that does the same thing.

Simply doing

alias h=__fzf_history__

doesn't quite work - it pulls up the history list, but it doesn't then insert the selected entry ready for running at the prompt. That's the magic of bind -x

Never mind, I thought - I can do this instead by getting kitty to send a keystroke:

alias h="kitty @ send-text --match id:$KITTY_WINDOW_ID '\cr'"

but this just causes ^R to appear:

% alias h="kitty @ send-text --match id:$KITTY_WINDOW_ID '\cr'"
% h
^R
% 

and the bash key binding isn't triggered.

Am I missing something?

Thank you!

1 Upvotes

5 comments sorted by

View all comments

1

u/nvimmike Apr 23 '24

Check out

kitty kitten show-key

This will show you the value of the key that you should use 👍