I am trying to use a function that shortens my bash prompt. I have added it in .bash_profile:
function last_two_dirs {
pwd |rev| awk -F / '{print $1,$2}' | rev | sed s_\ _/_
}
export PS1='$(last_two_dirs) $(__git_ps1) ➡ '
But I get an error bash: rev: command not found everytime I launch git bash.
I have set the PATH correctly since other commands work correctly except rev. Is rev not part of git bash? Or is there any other way to show only the parent and the current directory for the bash prompt?
OS: Windows 10
Your environment doesn't seem to have the rev command. However, you don't need it, there are built-in facilities for what you want to do.
To get the current working directory in your PS1, use \w:
PS1='\w\$ '
This gets you the full path, so your prompt will look something like
~/tinker/so/subdir/subsubdir$
Now, set the $PROMPT_DIRTRIM variable to the number of trailing directories to retain:
PROMPT_DIRTRIM=2
This will get you a prompt like
~/.../subdir/subsubdir$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With