Set a custom prompt in zsh [zshell] in Mint14

Write tutorials here
There are more tutorials here
Forum rules
Do not start a support topic here please. Before you post please read this

Set a custom prompt in zsh [zshell] in Mint14

Postby jawgrape on Sun Mar 24, 2013 6:05 pm

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.[I have not tested this]

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.

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.
Level 1
Level 1
Posts: 29
Joined: Tue Mar 12, 2013 9:10 pm

Linux Mint is funded by ads and donations.

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests