From 2a08e1acef2ec82c06ed2eea2fa7b437c48d8e58 Mon Sep 17 00:00:00 2001 From: rootiest Date: Fri, 5 Jun 2026 19:46:54 -0400 Subject: [PATCH] feat(shell): add fzf inline picker bound to @@ Adds __fzf_inline_picker function and @@ keybinding (Emacs + all Vi modes). Opens an fzf session and injects the selected item at the cursor position in the current command line. Includes SYNOPSIS/ DESCRIPTION doc block per project conventions. Updates README with new binding in the User Bindings table. --- README.md | 1 + conf.d/key_bindings.fish | 2 ++ functions/__fzf_inline_picker.fish | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 functions/__fzf_inline_picker.fish diff --git a/README.md b/README.md index ffa0abc..3c8d5bd 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ Beyond standard shell and FZF bindings, these custom interactive shortcuts are a | `Ctrl+Alt+U` | Replace Command Token | Strips the first token (the command) from the current line. **If the line is empty**, it pulls the previous command and strips its first token, placing the cursor at the start for a quick replacement (e.g., changing `mkdir` to `cd` while keeping the paths). | | `Ctrl+Alt+=` | Inline Qalculate! Evaluation | Passes the current command-line buffer to `qalc` (Qalculate!) and prints the result, then clears the buffer. Allows rapid-fire math without leaving the shell — type `150 * 1.08`, press `Ctrl+Alt+=`, and see `162` immediately. | | `Ctrl+Enter` | Smart Execute | Context-aware Enter key. Empty buffer → standard Enter. Buffer ending with `=` → evaluates it as a math expression via `qalc` (same as `Ctrl+Alt+=`). Any other content → executes the command normally. | +| `@@` | FZF Inline Picker | Opens an interactive `fzf` session and injects the selected item directly at the cursor position in the current command line. Useful for inserting file paths, branch names, or any fzf-searchable content mid-command. | --- diff --git a/conf.d/key_bindings.fish b/conf.d/key_bindings.fish index 8b8dd06..109f3ca 100644 --- a/conf.d/key_bindings.fish +++ b/conf.d/key_bindings.fish @@ -54,6 +54,7 @@ function fish_user_key_bindings bind ctrl-alt-u _replace_command_token type -q qalc && bind ctrl-alt-= _qalc_eval bind ctrl-enter _smart_execute + bind @@ __fzf_inline_picker # Set bindings for all Vi modes: # 'default' is Vi-Command, 'insert' is Vi-Insert, 'visual' is Vi-Visual @@ -63,5 +64,6 @@ function fish_user_key_bindings bind --mode $mode ctrl-alt-u _replace_command_token type -q qalc && bind --mode $mode ctrl-alt-= _qalc_eval bind --mode $mode ctrl-enter _smart_execute + bind --mode $mode @@ __fzf_inline_picker end end diff --git a/functions/__fzf_inline_picker.fish b/functions/__fzf_inline_picker.fish new file mode 100644 index 0000000..3485b0b --- /dev/null +++ b/functions/__fzf_inline_picker.fish @@ -0,0 +1,29 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# SYNOPSIS +# __fzf_inline_picker +# +# DESCRIPTION +# Opens an interactive fzf session and injects the selected item directly +# into the command line at the cursor position. Bound to @@ by default. +# Requires fzf to be installed. Repaints the prompt after insertion. +# +# RETURNS +# 0 A selection was made and inserted into the command line +# 0 No selection was made (fzf cancelled); command line is unchanged +# +# EXAMPLE +# # Press @@ at the prompt — fzf opens, pick an item, it appears at cursor +# +function __fzf_inline_picker + # Open fzf and capture selection + set -l selection (fzf) + + if test -n "$selection" + # Injects text instantly at the cursor + commandline -i (string escape -- $selection) + end + # Refresh the line display + commandline -f repaint +end