Get current directory, not path, in a function .bashrc
I would like to display a * in my prompt if the name of the current rvm gemset does not match the name of the current directory. I can get the name of the current gemset with no problem by using $(~/.rvm/bin/rvm-prompt g)
which, if the gemset is foo, will return @foo
.
I've tried both "@${PWD##*/}"
and "@${\W}"
but unfortunately with no success. My entire function looks like this:
function ps1_rvm() {
[[ $(~/.rvm/bin/rvm-prompt g) != "@${PWD##*/}" ]] && echo "*"
}
I am then using this function to set the value of PS1 so that it is output to my prompt.
Edit: I开发者_StackOverflow want to get the directory name, not the path.
Have you tried
function ps1_rvm() {
[[ $(~/.rvm/bin/rvm-prompt g) != $(basename $(pwd)) ]] && echo "*"
}
? That should work...
精彩评论