Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the prompt in oh my zsh and add hostname to it?

My oh my zsh prompt reads something like:

tenant-application git:(beta-4-1) 

I want it to read something like:

homestead tenant-application git:(beta-4-1) 

Or something similar where I can understand the hostname of the machine

When I do echo $PROMPT, it says

${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)

I tried:

export PROMPT=${ret_status} ${hostname} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)

But the error said:

zsh: not an identifier: %{^[[36m%}%c%{^[[00m%}

What am I doing wrong and how to make the right thing permanent?

like image 624
Rohan Avatar asked Feb 07 '17 07:02

Rohan


1 Answers

Add quotes to avoid immediate expansion of your expressions. Further the hostname up to the first dot can be inserted by using %m or the full hostname with %M (see http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html)

So this command should work:

export PROMPT='${ret_status} %m %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'

To make this permanent you can just add this line to your .zshrc file in your home directory.

like image 83
Markus Ankenbrand Avatar answered Oct 16 '22 05:10

Markus Ankenbrand