Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/widgets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ Due to Nushell's [unique design](https://www.nushell.sh/book/thinking_in_nu.html

By default, `Ctrl+G` is assigned to launching **navi** (in xonsh can be customized with `$X_NAVI_KEY`, see [xontrib-navi](https://github.com/eugenesvk/xontrib-navi) for details).

There's currently no way to customize the widget behavior out-of-the-box. If you want to change the keybinding or the **navi** flags used by the widget, please:
To customize the keybinding, use the `--key` flag with your shell's native keybinding syntax:

```sh
# zsh — bind to Ctrl+Space
eval "$(navi widget zsh --key '^ ')"

# bash — bind to Ctrl+Space
eval "$(navi widget bash --key '\C- ')"

# fish — bind to Ctrl+Space
navi widget fish --key '\c ' | source
```

If you want to further customize the widget behavior (e.g., change the **navi** flags), you can:

1. run, e.g., `navi widget bash` in your terminal
2. copy the output
Expand Down
4 changes: 2 additions & 2 deletions shell/navi.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _navi_widget_legacy() {
}

if [ ${BASH_VERSION:0:1} -lt 4 ]; then
bind '"\C-g": " \C-b\C-k \C-u`_navi_widget_legacy`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
bind '"__NAVI_KEY__": " \C-b\C-k \C-u`_navi_widget_legacy`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
else
bind -x '"\C-g": _navi_widget'
bind -x '"__NAVI_KEY__": _navi_widget'
fi
2 changes: 1 addition & 1 deletion shell/navi.plugin.elv
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ fn call-navi {
}
}

set edit:insert:binding[Alt-h] = { call-navi >/dev/tty 2>&1 }
set edit:insert:binding[__NAVI_KEY__] = { call-navi >/dev/tty 2>&1 }
4 changes: 2 additions & 2 deletions shell/navi.plugin.fish
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ function _navi_smart_replace
end
end

bind \cg _navi_smart_replace
bind --mode insert \cg _navi_smart_replace
bind __NAVI_KEY__ _navi_smart_replace
bind --mode insert __NAVI_KEY__ _navi_smart_replace
4 changes: 2 additions & 2 deletions shell/navi.plugin.nu
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export def navi_widget [] {

let nav_keybinding = {
name: "navi",
modifier: control,
keycode: char_g,
modifier: __NAVI_KEY_MODIFIER__,
keycode: __NAVI_KEY_CODE__,
mode: [emacs, vi_normal, vi_insert],
event: {
send: executehostcommand,
Expand Down
2 changes: 1 addition & 1 deletion shell/navi.plugin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ $null = New-Module {
}
}

Set-PSReadlineKeyHandler -BriefDescription "A keybinding to open Navi Widget" -Chord Ctrl+g -ScriptBlock { Invoke-NaviWidget }
Set-PSReadlineKeyHandler -BriefDescription "A keybinding to open Navi Widget" -Chord __NAVI_KEY__ -ScriptBlock { Invoke-NaviWidget }
Export-ModuleMember -Function @()
}
2 changes: 1 addition & 1 deletion shell/navi.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ _navi_widget() {
}

zle -N _navi_widget
bindkey '^g' _navi_widget
bindkey '__NAVI_KEY__' _navi_widget
28 changes: 28 additions & 0 deletions src/commands/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ impl Display for Shell {
pub struct Input {
#[clap(ignore_case = true, default_value_t = Shell::Bash)]
pub shell: Shell,
/// Custom keybinding for the widget, in shell-native syntax.
/// Defaults: bash='\C-g', zsh='^g', fish='\cg', elvish='Alt-h', powershell='Ctrl+g'.
/// For nushell, use 'modifier:keycode' format (e.g., 'control:char_g').
#[clap(long)]
pub key: Option<String>,
}

impl Runnable for Input {
Expand All @@ -40,6 +45,29 @@ impl Runnable for Input {
Shell::Powershell => include_str!("../../shell/navi.plugin.ps1"),
};

let content = match shell {
Shell::Bash => content.replace("__NAVI_KEY__", self.key.as_deref().unwrap_or("\\C-g")),
Shell::Zsh => content.replace("__NAVI_KEY__", self.key.as_deref().unwrap_or("^g")),
Shell::Fish => content.replace("__NAVI_KEY__", self.key.as_deref().unwrap_or("\\cg")),
Shell::Elvish => content.replace("__NAVI_KEY__", self.key.as_deref().unwrap_or("Alt-h")),
Shell::Nushell => {
let (modifier, keycode) = if let Some(ref key) = self.key {
let parts: Vec<&str> = key.splitn(2, ':').collect();
if parts.len() == 2 {
(parts[0].trim(), parts[1].trim())
} else {
("control", parts[0].trim())
}
} else {
("control", "char_g")
};
content
.replace("__NAVI_KEY_MODIFIER__", modifier)
.replace("__NAVI_KEY_CODE__", keycode)
}
Shell::Powershell => content.replace("__NAVI_KEY__", self.key.as_deref().unwrap_or("Ctrl+g")),
};

println!("{content}");

Ok(())
Expand Down