Ble.sh and atuin

Hi,

I’ve been using atuin for over a year now and it’s great, could never go back.

However I recently found ble.sh and wanted to start using some of those features alongside atuin. However out of the box ble.sh does not play nicely with atuin.

I made some progress here, and have atuin opening on CTRL-R and any commands I type going correctly into history. However when I select a command in atuin it gets printed above my prompt rather than inserted into it.

Any tips for getting this final piece of the puzzle working?

Here are the relevant bits of my config that got me this far:

.bashrc:

source /usr/share/blesh/ble.sh --noattach
 # ... lots of unrelated bash config.. then at the end of .bashrc :
 # Atuin                                                                                                       
 # (these bindings are overwitten by ble fzf contrib, in blerc we restore them                                 
 eval "$(atuin init bash)"                                                                                     
                                                                                                              
 [[ ! ${BLE_VERSION-} ]] || ble-attach                                                                         

My .blerc looks like this:

# Set up fzf                                                                                                        
ble-import -d integration/fzf-completion                                                                            
ble-import -d integration/fzf-key-bindings                                                                          
                                                                                                                    
# Restore atuin search after fzf has been loaded                                                                    
ble/util/idle.push '                                                                                                
  ble-bind -m emacs   -x C-r "atuin search -i"                                                                      
  ble-bind -m vi_imap -x C-r "atuin search -i"                                                                      
  ble-bind -m vi_nmap -x C-r "atuin search -i"                                                                      
'                                                                                                                                                             

Any help would getting the command I search for in atuin inserted into my prompt (rather than printed above it) would be much appreciated :folded_hands:

ble.sh, version 0.4.0-devel4+4338bbf7 (noarch)
atuin 18.4.0

This doesn’t restore the original keybindings as you expect. The unix command bound by C-r is not atuin search -i but __atuin_history as described in Bash - Key Bindings - Atuin Docs.

If you want to be further precise in restoring the keybindings, you can use the following settings:

# Restore atuin search after fzf has been loaded                                                                    
ble/util/idle.push '                                                                                                
  ble-bind -m emacs   -x C-r "__atuin_history --keymap-mode=emacs"                                                                      
  ble-bind -m vi_imap -x C-r "__atuin_history --keymap-mode=vim-insert"                                                                      
  ble-bind -m vi_nmap -x C-r "__atuin_history --keymap-mode=vim-normal"                                                                      
'

However, the root cause of the present problem is the initialization order of the fzf plugin. If the fzf plugin is properly loaded, the above workaround wouldn’t be needed in the first place.

A possible issue and solution for the initialization order of the fzf plugin are described in Sec 2.6 - ble.sh README. I think it is easier to defer the Atuin initialization until integration/fzf-key-bindings is loaded:

diff --git a/bashrc b/bashrc
index e7ee352b..2c7b3552 100644
--- a/bashrc
+++ b/bashrc
@@ -1,7 +1,7 @@
 source /usr/share/blesh/ble.sh --noattach
 # ... lots of unrelated bash config.. then at the end of .bashrc :
-# Atuin
-# (these bindings are overwitten by ble fzf contrib, in blerc we restore them
-eval "$(atuin init bash)"
+# Atuin (deferred until integration/fzf-key-bindings are loaded so
+# that Atuin overwrites the fzf keybindings)
+ble-import -C 'eval "$(atuin init bash)"' integration/fzf-key-bindings

 [[ ! ${BLE_VERSION-} ]] || ble-attach

Then you don’t need ble/util/idle.push '...' in your ~/.blerc.

1 Like