Skip to content

Add --key flag to navi widget for custom keybindings#1024

Open
knpwrs wants to merge 1 commit into
denisidoro:masterfrom
knpwrs:widget-custom-keybinding
Open

Add --key flag to navi widget for custom keybindings#1024
knpwrs wants to merge 1 commit into
denisidoro:masterfrom
knpwrs:widget-custom-keybinding

Conversation

@knpwrs

@knpwrs knpwrs commented Apr 14, 2026

Copy link
Copy Markdown

Summary

  • Adds a --key flag to navi widget so users can customize the keybinding without manually editing widget output
  • Shell plugin scripts now use template placeholders (__NAVI_KEY__) that are populated at runtime with the default or user-provided value
  • Updates widget documentation with examples

Usage

# zsh — bind to Ctrl+Space instead of Ctrl+G
eval "$(navi widget zsh --key '^ ')"

# bash
eval "$(navi widget bash --key '\C- ')"

# fish
navi widget fish --key '\c ' | source

Without --key, behavior is unchanged (defaults to Ctrl+G for most shells, Alt+H for elvish).

Context

Related to #837 — while that issue is about zellij support, it touches on the broader need to customize how navi integrates with different terminal environments. Ctrl+G is the default unlock for zellij.

The widget docs previously stated: "There's currently no way to customize the widget behavior out-of-the-box" — this text was added by the project creator in PR #480 (commit a8ddc13, April 2021). The PR body and comments are empty, and I couldn't find any related issues or discussion suggesting this was a deliberate design constraint rather than simply the state of things at the time.

Alternative approach

The same effect can be achieved today by rebinding after eval. For example in zsh:

eval "$(navi widget zsh)"
bindkey '^ ' _navi_widget
bindkey -r '^g'

This works because the widget's eval registers the _navi_widget function and zle widget — the subsequent bindkey calls just reassign the trigger key. The --key flag makes this a one-liner instead.

So as an alternative to this PR we can also update the docs.

Test plan

  • navi widget zsh outputs bindkey '^g' (default preserved)
  • navi widget zsh --key '^ ' outputs bindkey '^ '
  • navi widget bash --key '\C- ' replaces both legacy and modern bind lines
  • navi widget fish --key '\c ' replaces both normal and insert-mode binds
  • navi widget nushell --key 'control:char_space' replaces modifier and keycode
  • navi widget powershell --key 'Ctrl+Space' replaces Chord value
  • navi widget elvish --key 'Ctrl-g' replaces binding key
  • No __NAVI_KEY__ placeholders leak in any shell's default output
  • cargo test passes

Shell widget scripts now use template placeholders that are populated
at runtime with either the default keybinding or a user-provided value
via `navi widget <shell> --key <binding>`.
@alexis-opolka

Copy link
Copy Markdown
Collaborator

Hi, just to let you know that I'll check the PR tomorrow. Sorry for the long wait.

@knpwrs

knpwrs commented Apr 24, 2026

Copy link
Copy Markdown
Author

No problem. I'm working around it in my dotfiles for the time being: https://github.com/knpwrs/dotfiles/blob/441c9621777b1914553a59d498554e9887e47527/lib/navi.zsh

@alexis-opolka

Copy link
Copy Markdown
Collaborator

Since there has been some PRs with helpful features merged, I'm planning to try and test it before making a (pre-release/release) version out of it.

It will help on the side of debian's packaging since the new version removes dependencies and adds some useful features and bug fixes.

I don't really know for now, I'll make a decision tomorrow after thinking about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants