I have two storage drives and am trying to configure my bashrc file to do this:
If the cwd is on drive B :
- Truncate the bash prompt to begin at the /home directory of the second drive
- Change the color of bash prompt to red to know I am working in the other drive.
So far I have been able to accomplish changing the color with the following code and can truncate the entire prompt to only show the basename by using the '\W' modifier -- but am struggling with how to trim the PROMPT_COMMAND by specifying a bottom directory...
i.e.
/media/devj/2a24a03f-99a1-44bd-9a53-341zdd68334b/home/dev --> /home/dev/
Solution: Thanks for the help, this is what I ended up doing:
#Check if we are accessing my home folder from secondary drive
#If so change the color and trim the filepath to secondary /home
bash_prompt_command() {
root_path=`pwd | awk -F/ '{print $(NF-(NF-2))}'`
if [ $root_path = media ]; then #Shared drive
#Trim path up to the home directory
trim_path=${PWD#/media/devj/9a84a09e-80e9-44bd-9a53-342e3d48334c/}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]$trim_path\[\033[38;5;214m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[38;5;214m\]$(parse_git_branch)\[\033[00m\]\$ '
fi
}
# init it by setting PROMPT_COMMAND
PROMPT_COMMAND=bash_prompt_command