From 434e8238d8604dd1efcf601867b73ef17d912490 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 2 Jan 2024 21:35:24 +0900 Subject: [PATCH] feat(bash): provide auto-complete source for ble.sh (#1487) * feat(bash): provide auto-complete source for ble.sh * docs(integration): mention the auto-complete source for ble.sh --- atuin/src/shell/atuin.bash | 18 ++++++++++++++++++ docs/docs/integrations.md | 15 +++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash index cf67034e..725b85c4 100644 --- a/atuin/src/shell/atuin.bash +++ b/atuin/src/shell/atuin.bash @@ -133,6 +133,24 @@ __atuin_history() { # shellcheck disable=SC2154 if [[ -n "${BLE_VERSION-}" ]] && ((_ble_version >= 400)); then ble-import contrib/integration/bash-preexec + + # Define and register an autosuggestion source for ble.sh's auto-complete. + # If you'd like to overwrite this, define the same name of shell function + # after the $(atuin init bash) line in your .bashrc. If you do not need + # the auto-complete source by atuin, please add the following code to + # remove the entry after the $(atuin init bash) line in your .bashrc: + # + # ble/util/import/eval-after-load core-complete ' + # ble/array#remove _ble_complete_auto_source atuin-history' + # + function ble/complete/auto-complete/source:atuin-history { + local suggestion + suggestion=$(atuin search --cmd-only --limit 1 --search-mode prefix "$_ble_edit_str") + [[ $suggestion == "$_ble_edit_str"?* ]] || return 1 + ble/complete/auto-complete/enter h 0 "${suggestion:${#_ble_edit_str}}" '' "$suggestion" + } + ble/util/import/eval-after-load core-complete ' + ble/array#unshift _ble_complete_auto_source atuin-history' fi precmd_functions+=(__atuin_precmd) preexec_functions+=(__atuin_preexec) diff --git a/docs/docs/integrations.md b/docs/docs/integrations.md index 85786357..27983add 100644 --- a/docs/docs/integrations.md +++ b/docs/docs/integrations.md @@ -5,3 +5,18 @@ Atuin automatically adds itself as an [autosuggest strategy](https://github.com/zsh-users/zsh-autosuggestions#suggestion-strategy). If you'd like to override this, add your own config after "$(atuin init zsh)" in your zshrc. + +## ble.sh auto-complete (Bash) + +If ble.sh is available when Atuin's integration is loaded in Bash, Atuin automatically defines and registers an auto-complete source for the autosuggestion feature of ble.sh. + +If you'd like to change the behavior, please overwrite the shell function `ble/complete/auto-complete/source:atuin-history` after `eval "$(atuin init bash)"` in your `.bashrc`. + +If you would not like Atuin's auto-complete source, please add the following setting after `eval "$(atuin init bash)"` in your `.bashrc`: + +```shell +# bashrc (after eval "$(atuin init bash)") + +ble/util/import/eval-after-load core-complete ' + ble/array#remove _ble_complete_auto_source atuin-history' +```