cd
每次更改工作目录时,您都可以加入以更改提示。我经常问自己如何入迷,
cd
但我认为我现在找到了解决方案。如何将此添加到您的
~/.bashrc
?:
## Wrapper function that is called if cd is invoked# by the current shell#function cd { # call builtin cd. change to the new directory builtin cd $@ # call a hook function that can use the new working directory # to decide what to do color_prompt}## Changes the color of the prompt depending# on the current working directory#function color_prompt { pwd=$(pwd) if [[ "$pwd/" =~ ^/home/ ]] ; then PS1='[ 33[01;32m]u@h:w[ 33[00m]$ ' elif [[ "$pwd/" =~ ^/etc/ ]] ; then PS1='[ 33[01;34m]u@h:w[ 33[00m]$ ' elif [[ "$pwd/" =~ ^/tmp/ ]] ; then PS1='[ 33[01;33m]u@h:w[ 33[00m]$ ' else PS1='u@h:w\$ ' fi export PS1}# checking directory and setting prompt on shell startupcolor_prompt