How to you configure the command prompt in Linux to show current directory? I want to be able to put settings for this in the .zshrc file.
如何在Linux中配置命令提示符以显示当前目录?我想要在。zshrc文件中设置。
3 个解决方案
#1
22
You can place this to your .zshrc
file
您可以将其放置到.zshrc文件中
export PS1="[%* - %D] %d %% "
出口PS1="[%* - %D] %D % "
%d
denotes the CWD
% d表示
For more details go here for example
要了解更多的细节,请访问这里
#2
6
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.
我使用“% 20 <…< % ~ % < <“在我$ PS1,所以如果一个前缀被发现在当前工作目录中,取而代之的是~:它使用$ HOME(取代了~),主目录的用户(取代了~用户),和目录定义为哈希- d(例如,如果一个人有哈希- d foo = $ HOME /道路/ /目录,这个目录是~ foo)所取代。% 20 <… <和%<<允许zsh截断左侧的目录(如果目录太长),以避免提示符太长。< p>
#3
1
Add ${PWD/#$HOME/~}
to your PROMPT variable. Or just $PWD
if you don't want it to show ~ for your home directory.
向提示变量中添加${PWD/#$HOME/~}。如果您不想让它为您的主目录显示~,那么只需$PWD。
#1
22
You can place this to your .zshrc
file
您可以将其放置到.zshrc文件中
export PS1="[%* - %D] %d %% "
出口PS1="[%* - %D] %D % "
%d
denotes the CWD
% d表示
For more details go here for example
要了解更多的细节,请访问这里
#2
6
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.
我使用“% 20 <…< % ~ % < <“在我$ PS1,所以如果一个前缀被发现在当前工作目录中,取而代之的是~:它使用$ HOME(取代了~),主目录的用户(取代了~用户),和目录定义为哈希- d(例如,如果一个人有哈希- d foo = $ HOME /道路/ /目录,这个目录是~ foo)所取代。% 20 <… <和%<<允许zsh截断左侧的目录(如果目录太长),以避免提示符太长。< p>
#3
1
Add ${PWD/#$HOME/~}
to your PROMPT variable. Or just $PWD
if you don't want it to show ~ for your home directory.
向提示变量中添加${PWD/#$HOME/~}。如果您不想让它为您的主目录显示~,那么只需$PWD。