Hi,
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.
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??
Okies. Cool
Or maybe Iâm mistaken.
https://archlinux.org/packages/extra/any/bash-completion/
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
compinit
For autosuggestions and syntax highlighting, install the following packages:
zsh-autosuggestions
zsh-syntax-highlighting
And add the following to your .zshrc
:
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#404040"
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
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.
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'
#Plugins
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
#History
export HISTFILE=~/.zsh_history
export HISTSIZE=10000
export SAVEHIST=10000
#fortune
#!/bin/zsh
fortune
#mcfly
eval "$(mcfly init zsh)"
export MCFLY_PROMPT="âŻ"
export MCFLY_KEY_SCHEME=vim
export MCFLY_FUZZY=2
export MCFLY_RESULTS=1000
export MCFLY_INTERFACE_VIEW=BOTTOM
export MCFLY_RESULTS_SORT=LAST_RUN
#starship
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="${LBUFFER#$EDITOR }"
LBUFFER="sudoedit $LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
else
LBUFFER="sudo $LBUFFER"
fi
}
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.
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
Youâre welcome. I didnât just write it right now of the top of my head, I stole it from that scriptâŚ
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.
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!
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.