For some time I really wanted to switch from bash to zsh. There is only one problem, I am very picky about my prompt. I use the terminal all day, and it took me a long time to get a hint look and behave the way I want it. By the way, I put it together from various sources and some of my own things, and this may contain errors or incorrectly written code. All I want to know is if someone knows a code that I can paste into my zshrc that would give me exactly the same invitation.
Two functions that I really like are a variable-length working directory that adjusts if pwd is too long, and the directory separator is a different color and then the names. This prompt also sets the name of the dynamic terminal.
I could not post a photo because of some kind of reputation or something, but here is the code.
my_prompt() { local NONE="\[\033[0m\]" local COLOR1="\[\033[0;30m\]" local COLOR2="\[\033[0;31m\]" local COLOR3="\[\033[0;32m\]" local COLOR4="\[\033[0;33m\]" local COLOR5="\[\033[0;34m\]" local COLOR6="\[\033[0;35m\]" local COLOR7="\[\033[0;36m\]" local COLOR8="\[\033[0;37m\]" local COLOR9="\[\033[1;30m\]" local COLOR10="\[\033[1;31m\]" local COLOR11="\[\033[1;32m\]" local COLOR12="\[\033[1;33m\]" local COLOR13="\[\033[1;34m\]" local COLOR14="\[\033[1;35m\]" local COLOR15="\[\033[1;36m\]" local COLOR16="\[\033[1;37m\]"
Another thing is that I do not like to do something like
echo \`pwd` | grep "/"
to get slashes of a different color, because I would also like to change the color of directory names as well
EDIT AND ANSWER:
Thanks Simont for your reply. I think your criticism is that I am not able to do the search - this is what I need to start with: basically I used the link number 2 the multi-color path in the tooltip
to get started. I came up with the following, its not perfect (i.e. Random colors ...) but it is a good starting template. The following is my current .zshrc:
prompt_working_dir() { # How many characters of the $PWD should be kept local PWDLEN=55 ## Indicate that there has been dir truncation local TRUNC=".." local DIR=${PWD##*/} local PWDLEN=$(( ( PWDLEN < ${#DIR} ) ? ${#DIR} : PWDLEN )) local TITLE_PWD=${PWD/#$HOME/\~/} local pwdoffset=$(( ${#TITLE_PWD} - PWDLEN )) if [ ${pwdoffset} -gt "0" ] then TITLE_PWD=${TITLE_PWD:$pwdoffset:$PWDLEN} TITLE_PWD=${TRUNC}/${TITLE_PWD#*/} fi IN=$TITLE_PWD arr=(${(s:/:)IN}) unset NEWDIR if [ "$arr[1]" "==" "~" ] then NEWDIR="%{$fg[blue]%}$arr[1]" #delete 1st element arr[1]=() for x in $arr do NEWDIR="${NEWDIR}%{$fg_bold[cyan]%}/%{$reset_color%}%{$fg[blue]%}$x" done elif [ "$arr[1]" "==" ".." ] then NEWDIR="%{$fg[blue]%}$x%{$fg_bold[cyan]%}/" #delete 1st element arr[1]=() for x in $arr do NEWDIR="${NEWDIR}%{$reset_color%}%{$fg[blue]%}$x%{$fg_bold[cyan]%}/" done else for x in $arr do NEWDIR="${NEWDIR}%{$fg_bold[cyan]%}/%{$reset_color%}%{$fg[blue]%}$x" done fi echo "${NEWDIR}" unset PWDLEN unset TRUNC unset DIR unset PWDLEN unset TITLE_PWD unset pwdoffset unset IN unset arr } setopt PROMPT_SUBST autoload -U colors && colors # set window title to user@host %directory----------- precmd () {print -Pn "\e]0;% n@ %M: %~\a"} SEP=":" PROMPT='%{$fg[blue]%}%m%{$reset_color%}'\ '%{$fg_bold[cyan]%}@%{$reset_color%}'\ '%{$fg[blue]%}%n%{$reset_color%}'\ '%{$fg_bold[cyan]%}$SEP%{$reset_color%}'\ '$(prompt_working_dir)%{$reset_color%}'\ '%{$fg_bold[cyan]%}ยป%{$reset_color%} '
source share