Fish-like autosuggestions for Bash — suggests commands as you type based on history.
Inspired by zsh-autosuggestions and fish shell, this pure-Bash script shows inline "ghost text" suggestions from your command history as you type.
As you type, a dimmed suggestion appears after your cursor showing the most recent matching command from history. The suggestion is non-intrusive — it won't execute unless you explicitly accept it.
$ kubectl get po▌ds -n production -o wide
↑ ghost text (dimmed gray)
| Key | Action |
|---|---|
→ (Right Arrow) |
Accept full suggestion |
End |
Accept full suggestion |
Alt+→ / Alt+F |
Accept next word |
↑ (Up Arrow) |
Cycle to next suggestion (or history if no suggestions) |
↓ (Down Arrow) |
Cycle to previous suggestion (or history if no suggestions) |
Ctrl+] |
Dismiss suggestion |
| Any typing | Suggestion updates live |
- Bash 4.0+ (check with
bash --version) - Terminal with ANSI color support (virtually all modern terminals)
git clone https://github.com/YOUR_USER/bash-autosuggestions.git
cd bash-autosuggestions
bash install.sh
source ~/.bashrc# Copy the script somewhere permanent
mkdir -p ~/.local/share/bash-autosuggestions
cp bash-autosuggestions.sh ~/.local/share/bash-autosuggestions/
# Add to your .bashrc
echo 'source ~/.local/share/bash-autosuggestions/bash-autosuggestions.sh' >> ~/.bashrc
# Reload
source ~/.bashrccurl -sL https://raw.githubusercontent.com/YOUR_USER/bash-autosuggestions/main/bash-autosuggestions.sh \
-o ~/.local/share/bash-autosuggestions/bash-autosuggestions.sh --create-dirs && \
echo 'source ~/.local/share/bash-autosuggestions/bash-autosuggestions.sh' >> ~/.bashrc && \
source ~/.bashrcSet these variables before sourcing the script in your .bashrc:
# Color of the ghost suggestion (ANSI SGR code)
# Default: "38;5;244" (medium gray)
# Examples:
# "38;5;240" - darker gray
# "38;5;248" - lighter gray
# "38;2;100;100;100" - 24-bit RGB gray
# "2" - dim text
BASH_AUTOSUGGEST_HIGHLIGHT="38;5;244"
# Strategy for finding suggestions
# "history" - most recent history match (default)
# "match_prev_cmd" - match conditioned on previous command
BASH_AUTOSUGGEST_STRATEGY="history"
# Ignore history entries matching this glob pattern
# Example: "cd *" to never suggest cd commands
BASH_AUTOSUGGEST_HISTORY_IGNORE=""
# Minimum input length before suggesting (default: 1)
BASH_AUTOSUGGEST_MIN_LENGTH=1
# Maximum number of candidates to collect (default: 50)
BASH_AUTOSUGGEST_MAX_CANDIDATES=50
source ~/.local/share/bash-autosuggestions/bash-autosuggestions.shSuggests the most recent command from history that starts with your current input.
Like history, but prioritizes matches whose preceding history entry matches the command you just ran. This provides context-aware suggestions — e.g., after running git add ., it'll suggest git commit -m "..." if that's what you typically do next.
Falls back to history strategy if no contextual match is found.
# Disable autosuggestions in the current shell (removes all bindings)
bash_autosuggest_disable
# Re-enable autosuggestions
bash_autosuggest_enable
# Toggle on/off (lightweight - keeps bindings)
bash_autosuggest_togglebash uninstall.shOr manually:
# Remove from .bashrc (delete the source line)
# Remove installed files
rm -rf ~/.local/share/bash-autosuggestions| Feature | bash-autosuggestions | ble.sh | zsh-autosuggestions |
|---|---|---|---|
| Shell | Bash | Bash | Zsh |
| Inline suggestions | ✅ | ✅ | ✅ |
| Multiple suggestions cycling | ✅ (Up/Down arrows) | ✅ | ❌ |
| Suggestion counter [N/M] | ✅ | ❌ | ❌ |
| Syntax highlighting | ❌ | ✅ | ❌ (separate plugin) |
| Partial accept (word) | ✅ | ✅ | ✅ |
| History strategy | ✅ | ✅ | ✅ |
| Completion strategy | ❌ | ✅ | ✅ |
| match_prev_cmd | ✅ | ❌ | ✅ |
| Pure Bash | ✅ | ✅ | N/A (Zsh) |
| Lightweight | ✅ (~470 LOC) | ❌ (large) | ✅ |
| Vim mode | ❌ | ✅ | ❌ |
| Install complexity | Low | Medium | Low |
When to use this: You want a lightweight, single-file, drop-in solution that adds fish-like history suggestions to Bash without replacing the entire line editor.
When to use ble.sh instead: You want a full-featured Bash line editor with syntax highlighting, advanced completion, vim modes, and more. ble.sh is a much larger and more capable project.
- Ensure Bash 4.0+:
echo $BASH_VERSION - Check your history is non-empty:
history | wc -l - Ensure
HISTFILEis set and readable - Make sure the script is sourced (not executed):
source bash-autosuggestions.sh
- Run
resetor pressCtrl+Lto refresh the terminal - This can happen if the terminal is resized during a suggestion
- Source
bash-autosuggestions.shafter other.inputrcorbindcustomizations - If using
fzf, source fzf's keybindings first
- Your terminal may use different escape sequences
- Check with
cat -vthen press the arrow key - Adjust the
bind -xentries in_bas_setupif needed
The script uses Bash's bind command to create macros for every printable character. Each macro inserts the character normally, then triggers an internal function (_bas_update) via Ctrl+_. This function:
- Reads the current
READLINE_LINE(what the user has typed) - Searches history in reverse for the most recent match
- Renders the untyped suffix as "ghost text" using ANSI escape codes (save cursor → print dimmed text → restore cursor)
Accept keys (→, End, Alt+→) modify READLINE_LINE and READLINE_POINT directly to insert the suggestion.
MIT