Optimizing Shell Autosuggest for Butterfish

Well, have no fear because weve got a solution for ya: optimizing shell autosuggest for Butterfish!

Butterfish is an amazing terminal emulator that comes with some pretty sweet features. One of those features is its built-in autocomplete system. But let’s be real, sometimes it can feel like youre playing a game of “guess the command” when using Butterfish’s default settings.

Luckily for us, there are ways to make this feature work better and faster! Here are some tips that will help you optimize your shell autosuggest in Butterfish:

1️ To set the stage, lets talk about the basics. Make sure you have enabled autocomplete by pressing Ctrl + Space or Fn + Space (depending on your keyboard setup). This should bring up a list of suggestions based on what you’ve already typed in the terminal.

2️ Next, lets talk about how to make those suggestions more relevant and helpful. One way to do this is by using the “fzf” plugin for Butterfish. Fzf stands for “Fuzzy Finder,” which means it can help you find what you’re looking for even if you don’t remember exactly what it’s called or where it’s located.

To install fzf, open up your terminal and run the following command:

# This script installs the "fzf" plugin for Butterfish, which is a "Fuzzy Finder" that helps find files and directories even if their names or locations are not fully remembered.

# To install fzf, the "brew" command is used to install packages on macOS.

# The "install" command is used to specify that the package "fzf" should be installed.

# The "fzf" package is installed using the "brew install" command.
brew install fzf

Once thats done, add this line to your `~/.config/butterfish/init.lua` file (create it if it doesn’t exist):

-- Load FZF plugin for autocomplete
-- Load the FZF plugin from the butterfly-plugin library and assign it to the variable "fzf"
local fzf = require("butterfly-plugin").load_plugin "fzf"

-- Configure FZF to use with autosuggest
-- Set up the FZF plugin with the following configurations
fzf.setup {
  -- Set the source of suggestions to be the output of `fzf` command
  sources = {"fzf"}, -- Set the source of suggestions to be the output of the "fzf" command
}

3️ Now that fzf is installed and configured, how to use it with autosuggest. When you press Ctrl + Space or Fn + Space (depending on your keyboard setup), the suggestions will now be powered by fzf! This means that instead of just showing a list of possible completions based on what youve already typed, fzf will search through all available commands and show you relevant options.

4️ To make this even better, let’s add some customization to our autosuggest settings. Open up your `~/.config/butterfish/init.lua` file again (or create it if it doesn’t exist) and add the following lines:

-- Configure FZF options for autocomplete
fzf.setup {
  -- Set the source of suggestions to be the output of `fzf` command with custom options
  sources = {"fzf", "command:-r 'grep -Ei \'^[[:alnum:]]+\' $(git rev-parse --show-toplevel)/. *'"},
  -- Set the previewer to be FZF's own previewer (instead of Butterfish' default)
  previewer = "fzf",
}

This will add a new source for autosuggest that searches through all available commands and shows you only those that start with an alphanumeric character. This can be helpful if you tend to use a lot of shortcuts or aliases in your terminal, as it will help you find them more easily.

5️ Finally, how to customize the autosuggest behavior even further. One way to do this is by using Butterfish’ built-in “snippets” feature. Snippets allow you to create predefined text snippets that can be inserted into your terminal with a single keystroke.

To add a new snippet, open up the Butterfish preferences (Cmd + , on Mac) and navigate to the “Snippets” tab. Click the “+” button to add a new snippet, then enter the text you want to insert when using this snippet. You can also customize other settings like whether or not to expand the snippet automatically, or what keystroke to use for triggering it.

And that’s it! With these tips and tricks, your shell autosuggest in Butterfish should be faster, more relevant, and easier to use than ever before.

SICORPS