开发者

Get current directory, not path, in a function .bashrc

开发者 https://www.devze.com 2023-03-27 11:41 出处:网络
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 $(~/.

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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号