I don’t set my theme in zsh. I use starship for it. I source starship in my zshrc. Starship has a separate configuration and supports those special characters you see called nerd fonts.
Those are commands to enhance autocompletions and define keybindings for them.
function theme_precmd {
local TERMWIDTH=$(( COLUMNS - ${ZLE_RPROMPT_INDENT:-1} ))
Grabs the current terminals max width and writes it into the TERMWIDTH variable.
PR_FILLBAR=""
PR_PWDLEN=""
Creates two variables that are empty and may be used later
local promptsize=${#${(%):---(%n@%m:%l)---()--}}
Sets the width for the local prompt when the user is not processing Ruby code or doing a PWD (Print Working Direstory). Then writes it into the promptsize variable.
local rubypromptsize=${#${(%)$(ruby_prompt_info)}}
Sets the width for the prompt when the user is processing Ruby code. Then writes it into the rubypromptsize variable.
local pwdsize=${#${(%):-%~}}
Sets the width for the prompt when the user is running the pwd command. Then writes it into the pwdsize variable.
# Truncate the path if it's too long.
if (( promptsize + rubypromptsize + pwdsize > TERMWIDTH )); then
(( PR_PWDLEN = TERMWIDTH - promptsize ))
If the prompt is too long, finds out the amount of characters it is bigger than the terminal width
It then checks if the user is using a UTF-8 based language and cuts the bar into multiple lines based on the width of the terminal, which is not really great as it doesn’t take into account where the line is being cut, so it could be mid word.
I was like you and had custimized my zsh prompt. It was fun to learn but not really practical (for me). So this is,why i switched to Starship.
These are my notes for my install where i did not use oh my zsh:
How to setup ZSH in Arch Linux
(1) Verify what shell is currently installed (default is bash).
$ echo $SHELL
(2) Install ZSH
sudo pacman -S zsh
(3) Install ZSH plugins
sudo pacman -S zsh-autosuggestions zsh-completions zsh-syntax-highlighting starship
yay -S nerd-fonts-jetbrains-mono
Note: Could substitute to package ‘nerd-fonts-hack’.
(4) Add the Nerd Font of your choice to your terminal (e.g Alacritty)
(a) Edit Alacritty configuration file and add your preferred Nerd Font.
sudo nano .config/alacritty/alacritty.yml
(b) Update the preferred font
Font configuration
font:
normal:
family: JetBrainsMono Nerd Font
style: Regular
bold:
family: JetBrainsMono Nerd Font
style: bold
Italic font face
italic:
family: JetBrainsMono Nerd Font
style: italic
(5) Configure ZSH basic User Configuration:
From terminal run ‘zsh’ which will start the wizard.
(6) Change the Current User to use ZSH Shell
–Must Log out and back in to get the change
chsh -s /usr/bin/zsh
(7) Setup ZSH Plugins and Starship Prompt
(a) Edit the .zshrc file
sudo nano ~/.zshrc
(b) Use the following .zshrc content in your configuration file:
Thanks for your suggestions, for entire day today I was scratching my mind in order to learn the methodologies involved, and was in trouble as I was seeing these lines for first time.Though I managed to make a simple looking prompt as you can see in above posts.
With the various suggestions from your side, I think I can try to learn it a more.
And also thanks to @NeoFax , for providing the meaning of the lines.
While it’s fine to do it like that, I would recommend against it (this is just my personal preference).
Just configure your terminal emulator to run Zsh.
This way, you can keep Bash as your user’s default shell, even though you’ll use it very, very rarely. The benefit is that if you need to use the TTY, you’ll still have Bash by default, which is simpler and just easier for troubleshooting. Also with SSH.
Yeah, that’s literally what I said in the post above:
You can check it like this (the current user’s default shell is Bash, but the currently running interactive shell is Zsh):
~🐸 echo $SHELL
/bin/bash
~🐸 echo $0
/bin/zsh
Like I said, that’s just my personal preference, I find it the most convenient. You’re, of course, free to chsh into Zsh, if you really want to… I wouldn’t, though.
The more you use a shell, the more proficient you’ll be with it. And it also doesn’t hurt to read about it, but it is necessary to apply in practice what you read, otherwise you’ll forget it.
Now, some fancy Zsh features like autosuggestions work rather poorly in the TTY, at least the way I have them configured, because of the limited colour palette in the TTY. In general, if I’m using the TTY, I’m using it because I can’t use my terminal emulator of choice – almost certainly I’m in troubleshooting mode and I don’t want to be distracted by a shell that is too fancy (even though, normally, that would be convenient).
Same thing with SSH, if it is not predictable from where I am accessing it, I may have limited terminal features. I could be using the TTY in one computer to SSH into another.
Finally, I like to keep my .zshrc branchless. I could have something like
if [[ $TERM = "xterm-256color" ]]; then
# use this setting
else
# use that setting
fi
but I don’t like doing that, branching just slows down the loading of .zshrc, makes it bigger and more difficult to read, and keeping and maintaining elif branches that I’m going to use in less than 1% of cases is just not something I want to do.
On the other hand, Bash is super predictable. It’s a powerful shell on its own, not much inferior to Zsh, except that it lacks ZLE and all its fancy features. I find Bash completely sufficient for TTY and I like its predictability with SSH.
I still use Zsh in more than 99% of all interactive shell sessions even if it is not my user’s default shell. And since the terminal is my preferred way of interacting with my computers, that’s a lot of hours I spend in Zsh.