

Ruby version and gemset in your Bash prompt? Yes sir!
source link: https://www.devroom.io/2010/04/25/ruby-version-and-gemset-in-your-bash-prompt-yes-sir/?utm_campaign=Feed%3A+ariejan+%28ariejan%7Cdevroom.io%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ruby version and gemset in your Bash prompt? Yes sir!
RVM is an easy way to switch between different ruby implementations and gemsets. If you don’t know about it, go check it out. If you do know about, you’ll know how annoying it is never to know which ruby version and gemset you’re currently using. Here is a nice .profile
hack that shows your current ruby version and optional gemset in your prompt.
Firstly, add the following function to your ~/.profile
:
function rvm_version {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
[ "$version" != "" ] && version="@$version"
local full="$version$gemset"
[ "$full" != "" ] && echo "$full "
}
Next, you can use this function in your prompt. Like this:
export PS1="\$(rvm_version) \w \$(parse_git_branch) \$ "
The results? For standard ruby 1.8.7
@1.8.7 ~ $
Or with the rails3
gemset enabled:
@1.8.7@rails3 ~ $
So, now you always know which ruby you’re using! Happy coding!
My site is free of ads and trackers. I record privacy-respecting usage statistics with Fathom.
Was this post helpful to you? Why not ☕ Buy me a coffee
Copyright © 1999-2020 Ariejan de Vroom <[email protected]>
Live now; make now always the most precious time. Now will never come again.
– Jean-Luc Picard
Recommend
-
387
URL shortening is nothing new, it was originally made popular due to the 140 character limit of Twitter and the 160 character limit of SMS messages. https://trimlink.site https://trimlink....
-
8
The Ruby core team cares a lot about Unicode, and this is why we have pretty good Unicode support in the language. Even though the Unicode standard evolves consta...
-
9
Bash on OSX versus Bash on Ubuntu and Upgrading Your Bash Feb 15, 2017 Bash is one of those things that you just don't think about all that much – until you want something that is apparently new. In my case I...
-
9
Which ruby version am I using — how to check? Are you not sure which Ruby version you are using right now? Wondering how to check it? Say no more. Here are two simple ways to check for it. In irb Ru...
-
7
Running bash command from Ruby (with your bash_profile) Whenever I try to automate some of my daily tasks, I end up with a mix of Ruby and Bash scripts. This is the time when I look up to the differences between
-
15
BASH your SVN and Trac installation! Posted: 2007-06-12 - Last updated: 2019-06-05 Tagged
-
6
Change Ruby version on Mac audience developer ...
-
4
Issues · magicmonty/bash-git-prompt · GitHub Clear current search query, filters, and sorts Author...
-
7
Bash: ^^}: bad substitution – upgrade your Bash version (macOS) This blog post is about a situation where you are capitalising an argument in bash and you get the following error: bash: ${sta...
-
6
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK