Dahao's Personal Website

How to Enable Syntax Highlighting and Autosuggestions in Bash (No sudo Required)

If you're stuck with Bash on a shared Linux system and don't have root access, you might think you're out of luck when it comes to quality-of-life features like syntax highlighting and fish-style autosuggestions. You're not. This guide walks through how to set up both using ble.sh entirely in your home directory.


What You'll Get


Step 1: Check if gawk is Available

ble.sh requires GNU Awk (gawk) to build. Check what's on your system:

which awk mawk gawk nawk
awk --version

If awk --version shows GNU Awk, you're good. If it shows something else (like mawk), you'll need to install gawk manually — see the next step.


Step 2: Install gawk Without sudo (if needed)

If gawk isn't available, build it from source into your home directory:

Note: You may want to change to the latest version of gawk in the following command.

wget https://ftp.gnu.org/gnu/gawk/gawk-5.3.0.tar.gz
tar -xf gawk-5.3.0.tar.gz
cd gawk-5.3.0
./configure --prefix=$HOME/.local
make && make install

Then make sure ~/.local/bin is on your PATH:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Verify it worked:

gawk --version  # should show GNU Awk

Step 3: Install ble.sh

Clone and build ble.sh into your home directory:

cd ~
git clone --recursive https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local

Step 4: Enable It in ~/.bashrc

ble.sh is an interactive line editor, so it should only run in interactive shells. Sourcing it unconditionally can break non-interactive contexts (scripts, scp, PBS jobs) and leave you with a shell where you can't type.

Open ~/.bashrc in an editor and add this block. Put the first part near the top of your interactive-shell section, and the second part at the very end of the file:

# Near the top (inside your interactive shell section if you have one):
if [[ $- == *i* ]] && [ -f ~/.local/share/blesh/ble.sh ]; then
    source ~/.local/share/blesh/ble.sh --attach=none
fi

# ... rest of your .bashrc ...

# At the very END of ~/.bashrc:
if [[ ${BLE_VERSION-} ]]; then
    bleopt complete_auto_history=1
    bleopt complete_auto_complete=1
    ble-attach
fi

Loading early but attaching at the end lets the rest of your .bashrc finish first, so ble.sh sees a stable environment.

Reload your shell:

source ~/.bashrc

All Done

From now on, every Bash session will have:


Troubleshooting

gawk could not be found during make — You have mawk or another awk variant. Follow Step 2 to build gawk from source.

Shell loads but you can't type anything — ble.sh is attaching in the wrong context. Reconnect with ssh -t user@host "bash --noprofile --norc" to get in without loading .bashrc, then fix the file to use the pattern in Step 4.

Suggestions not appearing — Make sure both bleopt lines are inside the final attach block and that you've reloaded with source ~/.bashrc.

Want an easier life? — Check if zsh is already installed:

which zsh

If it returns a path, you can switch to it with no sudo required:

chsh -s $(which zsh)

Zsh has a much richer plugin ecosystem (zsh-autosuggestions, zsh-syntax-highlighting) and these features work out of the box with Oh My Zsh.