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
elif [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
PR_FILLBAR="\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize) ))::${PR_HBAR}:)}"
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.
else
PR_FILLBAR="${PR_SHIFT_IN}\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize) ))::${altchar[q]:--}:)}${PR_SHIFT_OUT}"
fi
}
If the user is not using a UTF-8 language it just cuts the code at the altchar(q) character.