How to you configure the command prompt in Linux to show current directory?
I use "%20<...<%~%<<"
in my $PS1
, so that if a prefix is found in the current working directory, it is replaced by ~
: it works with $HOME
(replaced by ~
), home directories of users (replaced by ~user
), and directories defined by hash -d
(e.g., if one has hash -d foo=$HOME/path/to/dir
, then this directory is replaced by ~foo
). The %20<...<
and %<<
allows zsh to truncate the directory on the left side if it is too long, in order to avoid a too long prompt.
You can place this to your .zshrc
file
export PS1="%d %% "
%d
denotes the CWD
For more details go here for example
Like Jiri Kremser said, you can change the prompt using PS1
variable. For example, if you want to change prompt to something like this (show the current path relative to HOME dir):
use the following setting in .zshrc
,
export PS1="[%~]$ "
Then source .zshrc
to make the change take effect.
The official zsh doc on prompt variables can be found here.