Customize color prompt in tcsh with conditional expression

27 views Asked by At

I would like to customize my prompt in tcsh as follows:

  • Print username (cyan)
  • Print current path (yellow)
  • Print "git" (in green) if the current folder is a git folder, else print "no_git" (in red)

I tried in this way and for the first 2 points it works as expected, but I'm not able to have the last point work with the conditional color, since the terminal gives me error "Missing ]."

set red='%{\033[0;31m%}'
set green="%{\033[0;32m%}"
set yellow="%{\033[0;93m%}"
set cyan="%{\033[0;36m%}"
set end="%{\033[0m%}"
alias precmd 'set git_folder=`sh -c "if git branch > /dev/null 2>&1; then echo '${green}git'; else echo '${red}no_git'; fi"`; \\
              set prompt = "${cyan}%B%n%b${end} ${yellow}%/${end} ${git_folder} ${end} > "'

I tried also with different types of quotes but then other errors occurred. Can anyone tell me how to do it? Thanks!!

0

There are 0 answers