um pluguinho
RVM, onde estou!?!?!
Comecei a utilizar o RVM em sua versão 0.0.22, na época ele não passava de um script shell que permitia a instalação e troca entre as vms, mas ele vem avançado muito, e funcionalidades como set de gemas é só a ponta do iceberg.
Motivado pelo post anterior acabei lendo um pouco mais a documentação e encontrei uns scriptizinho bem interessante. Como saber rapidamente qual a versão atual da minha VM? Para isso podemos contar com o script ~/.rvm/bin/rvm-prompt, ele pode ser usando adicionando a seguinte linha ao seu .bash_profile:
Com isso ele mostra qual maquina virtual do Ruby você esta usando, mas apenas quando essa for diferente da default. Só isso já seria o suficiente, mas o que me incomoda nesta solução, é que eu já tenho uma linha de comando grande, e nem sempre eu preciso saber qual versão eu estou usando, isso é particularmente interessante quando estou em um projeto Ruby. Como normalmente um projeto Ruby temos um arquivo Rakefile podemos procurar por este arquivo e exibir a versão da máquina apenas quando estivermos no diretório de um projeto Ruby. Vamos adicionar as seguintes linhas ao nosso .bash_profile:
RVM_VERSION=`~/.rvm/bin/rvm-prompt`
if [[ -f "$(pwd)/Rakefile" ]] && [[ ! -z "$RVM_VERSION" ]]; then
echo "${RVM_VERSION} "
fi
}
Agora podemos mudar a linha anterior para:
Espero que ajude alguém e qualquer dica que possa melhor é só comentar a baixo.
| Print article | This entry was posted by Éverton Antônio on November 24, 2009 at 3:00 pm, and is filed under Configuração, Desenvolvimento, Ruby/Rails. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 2 years ago
If you are using the latest version of rvm (rvm update –head) then you can take advantage of a few new features, namely hooks and the new project specific ‘.rvmrc’ file.
Let’s say I have my project directory as ~/projects/ and in this directory I have two projects ‘projecta’ and ‘projectb’. Project a is supposed to run on jruby all the time and projectb is supposed to run on ree 1.8.7. The setup:
echo “rvm jruby%projecta” > ~/projects/projecta/.rvmrc
echo “rvm ree%projectb” > ~/projects/projectb/.rvmrc
# notice the ‘ so that the “$” does not get interpreted by the shell:
echo ‘echo “Now using $rvm_ruby_string”‘ ~/.rvm/hooks/after_use
Then if I type this:
“cd ~/projects/projecta” I will then be running jruby with ‘projecta’ gem set and see the output ‘Now using jruby-1.4.0′. If I then “cd ~/projects/projectb” I will then be running ree with a ‘projectb’ gem set and see the output ‘Now using ree-1.8.7-2009.10′
By using the ~/.rvm/hooks/after_use hook every time I use a new ruby with rvm the echo statement gets executed in that context so for example:
∴ rvm 1.9.1
Now using ruby-1.9.1-p243
Enjoy, and thank you for using rvm!
~Wayne
about 2 years ago
Show!!
Bom, eu coloquei deixei aparecendo sempre porque a maior parte do tempo eu estou trabalhando com ruby mesmo. Dei uma modificada no meu PS1 para fica de uma forma que mais me agrada. Ta aí completo, com branch do git, cores e tudo mais:
PS1=’\n[\u] \[33[1;33m\]\w\a\[33[0m\]$(__git_ps1 ” \[33[1;32m\](%s)\[33[0m\]“) \[33[0;31m\]$(~/.rvm/bin/rvm-prompt)33[0m\]\n\$ ‘
about 2 years ago
Hi Wayne,
Very nice tip, I’m using version 0.0.82, and worked perfectly here is.
Thank you for creating rvm, surely one of the best tools I’ve ever used.
about 2 years ago
That is great to hear, thank you
Additionally I should mention that rvm-prompt also takes command line arguments so you can do things like this:
∴ ~/.rvm/bin/rvm-prompt i v
[ruby-1.9.1]
∴ ~/.rvm/bin/rvm-prompt i p
[ruby-p243]
∴ ~/.rvm/bin/rvm-prompt v p
[1.9.1-p243]
~Wayne
about 2 years ago
@Everton, ótimo complemento para o post anterior. Show de bola !!!
@Wayne, really great tip. I’ve already incorporated in my prompt
about 2 years ago
I have updated the documentation for:
rvmrc files: http://rvm.beginrescueend.com/rvmrc/
rvm-prompt: http://rvm.beginrescueend.com/prompt/
rvm hooks: http://rvm.beginrescueend.com/hooks/
Enjoy!
~Wayne