terminal: Add fzf file insertion and zoxide cd key binds

The following is added to all three shells bash, zsh, nushell:

Pressing c-t at any time lets you insert a file/dir at the current
cursor location using fzf. Same for 'T' in vicmd mode.

Pressing alt-c at any time lets you jump to that directory using zoxide,
with the zle editor content intact. Same for 'C' in vicmd mode.

Zsh implementation from: https://github.com/ajeetdsouza/zoxide/issues/357
Bash implementation: https://github.com/ajeetdsouza/zoxide/issues/516

Nushell implementation taken from: https://github.com/junegunn/fzf/issues/4122

TODO: Nushell fzf mapping has one problem in that it does not quote the
selected file in any way. So any file with e.g. a space in it will have
to be manually fixed afterwards.
This commit is contained in:
Marty Oehme 2025-10-12 13:23:42 +02:00
parent 40e8287213
commit fa7e740249
Signed by: Marty
GPG key ID: 4E535BC19C61886E
3 changed files with 101 additions and 14 deletions

View file

@ -38,18 +38,18 @@ zoxide init nushell | save -f ($nu.data-dir | path join "vendor/autoload/zoxide.
# load carapace completions
source ~/.cache/carapace/init.nu
# keybinds
$env.config.keybindings = [
{ modifier: control keycode: char_o mode: [emacs, vi_normal, vi_insert] event: null },
{
name: clear_screen
modifier: control
keycode: char_t
modifier: alt
keycode: char_l
mode: ["emacs", "vi_normal", "vi_insert"]
event: {
send: ClearScreen
}
event: [
{edit: Clear}
{send: Enter}
]
}
{
name: open_editor
@ -60,6 +60,41 @@ $env.config.keybindings = [
send: OpenEditor
}
}
{
name: run_zoxide
modifier: alt
keycode: char_c
mode: ["emacs", "vi_normal", "vi_insert"]
event: {
send: executehostcommand
cmd: "zoxide query --interactive"
}
}
{
name: run_zoxide_vicmd
modifier: shift
keycode: char_c
mode: [ "vi_normal"]
event: {
send: executehostcommand
cmd: "zoxide query --interactive"
}
}
{
name: insert_file_fzf
modifier: control
keycode: char_t
mode: ["emacs", "vi_normal", "vi_insert"]
event: {
send: executehostcommand
cmd: "
let fzf_ctrl_t_command = \$\"fd --type file --hidden | fzf --preview 'bat --color=always --style=full --line-range=:500 {}' \";
let result = nu -l -i -c $fzf_ctrl_t_command;
commandline edit --append $result;
commandline set-cursor --end
"
}
}
]
alias l = ls