How to have autocomplete in terminal?

While I watch videos regarding linux. Most of the Youtubers command line has some auto suggestions of the command or the location. In the pic, he just typed cd and wayland location was auto suggested.How they do that??


I see you using zsh.Take a look here: Looks like that’s what you’re looking for.

1 Like

What you see there is a command history. The user once used cd .config/waybar in the past and the ZSH shell saved that command. So if the user starts typing cd, he gets a history of all the commands that you used with cd. You can cycle through them with arrow up/down.

This feature is a standard option of ZSH and can be activated by putting this inside your .zshrc:

zstyle ‘:completion:*’ menu select

Check out the arch wiki on how to change to the ZSH shell.

is this feature available in bash??

I don’t think it is. Bash only has a simple history, AFAIK.

Okies. Cool :v:

Or maybe I’m mistaken.

You could try to install that package and add this to your .bashrc

source /usr/share/bash-completion/bash_completion

edit: This probably isn’t it. It seems to be only completions for known commands not the history.

I use Zsh, and I have auto-completion (that is a menu that I invoke with Tab) and also auto-suggestions, as well as syntax highlighting.

If you look up online how to set that up, most “tutorials” will tell you to use Oh-My-Zsh. These people are idiots misguided, do not listen to them. Oh-My-Zsh is a bloated mess that slows down your terminal, and you don’t need that.

Auto-completion with a nice menu comes with Zsh, out of the box, just add something like this to your .zshrc:

zstyle :compinstall filename '/home/kresimir/.zshrc'
autoload -Uz compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' rehash true
zmodload zsh/complist

For autosuggestions and syntax highlighting, install the following packages:


And add the following to your .zshrc:

source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_STRATEGY=(history completion)

Of course, you can use any colour for that.

source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)

And you can define your colours after that. See the documentation on how to do that.

There is also a package called zsh-autocomplete but I find it to be a total overkill, it’s too distracting.

1 Like

I think there are less offensive ways to provide suggestions…

I used oh-my-zsh for a long time. As you say, a lot of bloat. Currently only zsh is in use. What i can’t do without, i got from the AUR. Among them zsh-syntax-highlighting, zsh-autosuggestions and zsh-sudo. I have to use AUR because i am not able to write scripts…

This is my .zshrc and for me it does what it should. Namely be functional for me.

# Created by newuser for 5.9
#exa alias
#exa alias
alias la="exa --long --all --group"
alias ll='exa -la --icons --octal-permissions --group-directories-first'
alias ls='exa -1 --icons --group-directories-first'

source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

source /usr/share/zsh/plugins/zsh-sudo/sudo.plugin.zsh

export HISTFILE=~/.zsh_history
export HISTSIZE=10000
export SAVEHIST=10000


eval "$(mcfly init zsh)"
export MCFLY_PROMPT="❯"
export MCFLY_FUZZY=2
export MCFLY_RESULTS=1000

eval "$(starship init zsh)"

I did not know that. Thanks for the hint. I must try if i can do that

zsh-autosuggestions and zsh-syntax-highlighting are from the repos, so it’s perfectly fine to use those. Only zsh-sudo is from the AUR.

Now, I looked at what zsh-sudo does: it inserts sudo at the beginning of your ZLE buffer if you press EscEsc. To me, that doesn’t seem like a killer feature, since I very rarely use sudo and often, it’s not even at the beginning of a line. And when I do use sudo, I prefer to type it out in full, as it gives me a second to ask the important question: “do I really need to use sudo here?”… But that’s just me.

If you really like that feature, you can use the version from the AUR, nothing wrong with that. Or, if you want to minimise your use of the AUR, you can just manually download the zsh script, put it somewhere in your home directory and source it in your .zshrc as you do now. Or, even simpler, you can just add this to your .zshrc:

sudo-command-line() {
    [[ -z $BUFFER ]] && zle up-history
    if [[ $BUFFER == sudo\ * ]]; then
        LBUFFER="${LBUFFER#sudo }"
    elif [[ $BUFFER == $EDITOR\ * ]]; then
        LBUFFER="sudoedit $LBUFFER"
    elif [[ $BUFFER == sudoedit\ * ]]; then
        LBUFFER="${LBUFFER#sudoedit }"
        LBUFFER="sudo $LBUFFER"
zle -N sudo-command-line
bindkey "\e\e" sudo-command-line
bindkey -M vicmd '\e\e' sudo-command-line

You don’t need this in your .zshrc, it does nothing, it’s just a comment that doesn’t provide any useful commentary.

1 Like

You can use something lighter than oh-my-zsh, I use Zap, it looks like this in my .zshrc :

# Plugins manager
[ -f "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" ] && source "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh"
plug "zsh-users/zsh-syntax-highlighting"
plug "zsh-users/zsh-autosuggestions"
plug "tom-auger/cmdtime"
plug "zsh-users/zsh-completions"
plug "Aloxaf/fzf-tab"
plug "smeagol74/zsh-fzf-pass"
plug "joshskidmore/zsh-fzf-history-search"
plug "Anant-mishra1729/web-search"
plug "zap-zsh/sudo"
plug "zpm-zsh/colorize"
plug "peterhurford/up.zsh"

Still bloat. Though, I guess it can’t be worse than Oh-My-Zsh, so it’s an improvement.

EDIT: Actually, I stand corrected… Zap acts as a package manager and downloads stuff from random git repos when it updates the plugins. That is a good way to install malware.

Oh yes, i also prefer to put sudo at the beginning. Sometimes i forget. For me it is a useful feature.

Wow, Thanks a lot. This works fine. I wish I could write a script that fast, let alone read and copy the small piece needed to represent a function.

Ok, so im out of AUR in zsh :wink:

1 Like

I don’t care as long as it’s practical for me, especially the plugin update :

You’re welcome. I didn’t just write it right now of the top of my head, I stole it from that script… :slight_smile:

That’s the only thing Oh-My-Zsh is good for, it contains a bunch of scripts that you can steal for yourself, or use it to learn ZLE scripting.

As I said, that’s a great way to get malware into your system (bypassing package management and cloning random git repos for scripts which you execute locally).

I’ve done my part and warned you, it’s your system, you decide what to do with it. :man_shrugging:


I don’t care about your gate keeping, concerning malware, not my fault if you’re not able to browse a github repo.

Yes, I’m sure you browse all the github repos for any diffs before you update your plugins. Riiiight.

Cool story! rofl

This post is sponsored by mixcase, a handy utility script for online discourse.

Most of the plugin that need an update are zsh-syntax-highlighting, zsh-completions and zsh-autosuggestions, the source used by your packages.