Skip to content

Commit

Permalink
feat(zsh): update widget names (#1631)
Browse files Browse the repository at this point in the history
The current widget names for Zsh start with "_", which gives an
impression to users that those widgets are internal API and should not
be bound by the users.  However, we actually instruct users to set up
custom keybindings by specifying them to bindkey.

In other shells, a separate namespace for widgets are not prepared, so
we want to prefix "_" to shell function names to tell the users that
these are not the commands that are supposed to be called from the
command line.  However, the widget names are separated in their own
namespace in Zsh, so we do not have to isolate them by prefixing "_".
In fact, other frameworks such as `fzf` define widgets with names not
starting with "_".

In this patch, we update the widget names to have the form "atuin-*".
The old widget names that existed in the release version <= 17.2.1 are
left for compatibility.
  • Loading branch information
akinomyoga committed Jan 29, 2024
1 parent bdcb143 commit 2ef5169
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
22 changes: 11 additions & 11 deletions atuin/src/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ impl Cmd {
println!("{base}");

if std::env::var("ATUIN_NOBIND").is_err() {
const BIND_CTRL_R: &str = r"bindkey -M emacs '^r' _atuin_search_widget
bindkey -M viins '^r' _atuin_search_viins_widget
bindkey -M vicmd '/' _atuin_search_widget";

const BIND_UP_ARROW: &str = r"bindkey -M emacs '^[[A' _atuin_up_search_widget
bindkey -M vicmd '^[[A' _atuin_up_search_vicmd_widget
bindkey -M viins '^[[A' _atuin_up_search_viins_widget
bindkey -M emacs '^[OA' _atuin_up_search_widget
bindkey -M vicmd '^[OA' _atuin_up_search_vicmd_widget
bindkey -M viins '^[OA' _atuin_up_search_viins_widget
bindkey -M vicmd 'k' _atuin_up_search_vicmd_widget";
const BIND_CTRL_R: &str = r"bindkey -M emacs '^r' atuin-search
bindkey -M viins '^r' atuin-search-viins
bindkey -M vicmd '/' atuin-search";

const BIND_UP_ARROW: &str = r"bindkey -M emacs '^[[A' atuin-up-search
bindkey -M vicmd '^[[A' atuin-up-search-vicmd
bindkey -M viins '^[[A' atuin-up-search-viins
bindkey -M emacs '^[OA' atuin-up-search
bindkey -M vicmd '^[OA' atuin-up-search-vicmd
bindkey -M viins '^[OA' atuin-up-search-viins
bindkey -M vicmd 'k' atuin-up-search-vicmd";

if !self.disable_ctrl_r {
println!("{BIND_CTRL_R}");
Expand Down
12 changes: 8 additions & 4 deletions atuin/src/shell/atuin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ _atuin_up_search_viins() {
add-zsh-hook preexec _atuin_preexec
add-zsh-hook precmd _atuin_precmd

zle -N atuin-search _atuin_search
zle -N atuin-search-vicmd _atuin_search_vicmd
zle -N atuin-search-viins _atuin_search_viins
zle -N atuin-up-search _atuin_up_search
zle -N atuin-up-search-vicmd _atuin_up_search_vicmd
zle -N atuin-up-search-viins _atuin_up_search_viins

# These are compatibility widget names for "atuin <= 17.2.1" users.
zle -N _atuin_search_widget _atuin_search
zle -N _atuin_search_vicmd_widget _atuin_search_vicmd
zle -N _atuin_search_viins_widget _atuin_search_viins
zle -N _atuin_up_search_widget _atuin_up_search
zle -N _atuin_up_search_vicmd_widget _atuin_up_search_vicmd
zle -N _atuin_up_search_viins_widget _atuin_up_search_viins
8 changes: 4 additions & 4 deletions docs/ru/key-binding_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ eval "$(atuin init zsh)"

# zsh

Autin устанавливает виджет ZLE "\_atuin_search_widget"
Autin устанавливает виджет ZLE "atuin-search"

```
export ATUIN_NOBIND="true"
eval "$(atuin init zsh)"
bindkey '^r' _atuin_search_widget
bindkey '^r' atuin-search
# зависит от режима терминала
bindkey '^[[A' _atuin_search_widget
bindkey '^[OA' _atuin_search_widget
bindkey '^[[A' atuin-search
bindkey '^[OA' atuin-search
```

# bash
Expand Down
8 changes: 4 additions & 4 deletions docs/zh-CN/key-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ eval "$(atuin init zsh)"

# zsh

Atuin 定义了 ZLE 部件 "\_atuin_search_widget"
Atuin 定义了 ZLE 部件 "atuin-search"

```
export ATUIN_NOBIND="true"
eval "$(atuin init zsh)"
bindkey '^r' _atuin_search_widget
bindkey '^r' atuin-search
# 取决于终端模式
bindkey '^[[A' _atuin_search_widget
bindkey '^[OA' _atuin_search_widget
bindkey '^[[A' atuin-search
bindkey '^[OA' atuin-search
```

# bash
Expand Down

0 comments on commit 2ef5169

Please sign in to comment.