Page 1 of 1

Set a custom prompt in zsh [zshell] in Mint14

Posted: Sun Mar 24, 2013 6:05 pm
by jawgrape
I like to use zsh rather than bash or some other shell at the terminal. I Iike to customize my prompt too, and the customization is different for different distros which drives me crazy, so I figured I would drop in a how to here. This is not all encompassing.

This is for zsh so it is going to be different if you are using a different shell at the terminal.

To customize the prompt for your local user you put this in your local .zshrc file which should reside in the users home directory. If you want to modify the global prompt theoretically it would go into /etc/zsh/zshrc.

So I wanted a prompt that is hostname- <current-working-directory> and wanted them in certain colors, so in my ~/.zshrc file I put this:

Code: Select all

 autoload -U colors && colors
 PS1="%B%{$fg[yellow]%}%m%b%{$fg[yellow]%}-%{$reset_color%} %{$fg[grey]%}%B%~ #%b%{$reset_color%} "
which produces something like this:
amber- ~ #
amber- /media/nas/rocks #

Most of the rest of it is self explanatory
%B = turn on Bold
%b = turn off Bold
%m = hostname
%~ = display pwd (print working directory)

Another example to try. Place this after the autoload command in the example above.

Code: Select all

PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
This page does a pretty good job of defining all of the different options you can use in your prompt. Note that the color code stuff does not work in Mint as it is described on the following page.
http://www.nparikh.org/unix/prompt.php

I have also seen references to:

Code: Select all

autoload -U promptinit && promptinit
as a way to use pre-installed prompts with zsh but I haven't actually tried it. Maybe others can comment on that.