2021-05-04 01:59:31 +00:00
|
|
|
# Ruby
|
2012-06-13 01:02:14 +00:00
|
|
|
|
|
|
|
Configures [Ruby][1] local gem installation, loads version managers, and defines
|
|
|
|
aliases.
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Local Gem Installation
|
2012-06-13 01:02:14 +00:00
|
|
|
|
|
|
|
When a Ruby version manager is not detected, local gems are installed in
|
2021-05-17 06:24:03 +00:00
|
|
|
_`~/.gem`_; otherwise, they are installed according to the manager.
|
|
|
|
|
|
|
|
## rbenv
|
|
|
|
|
|
|
|
An alternative RVM is to use [_rbenv_][2], which allows for switching between
|
|
|
|
multiple, isolated Ruby installations in the home directory.
|
|
|
|
|
|
|
|
While it is not as feature rich as RVM, it is not loaded into the shell and is
|
|
|
|
not known to cause conflicts with shell scripts.
|
|
|
|
|
|
|
|
This will be loaded automatically if _rbenv_ is installed to `$RBENV_ROOT`,
|
|
|
|
_`~/.rbenv`_, or if the `rbenv` command is on the path.
|
2012-06-13 01:02:14 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## rvm
|
2012-06-13 01:02:14 +00:00
|
|
|
|
2021-05-17 06:24:03 +00:00
|
|
|
An alternative to the above is to use [The Ruby Version Manager (_rvm_)][3],
|
2021-05-04 01:59:31 +00:00
|
|
|
which allows for managing multiple, isolated Ruby installations and gem sets in
|
|
|
|
the home directory.
|
2012-06-13 01:02:14 +00:00
|
|
|
|
|
|
|
Since RVM is loaded into the shell and is known to override shell commands, it
|
|
|
|
may conflict with shell scripts.
|
|
|
|
|
2014-02-18 04:39:08 +00:00
|
|
|
Load this module as late as possible when using RVM since RVM will complain if
|
|
|
|
it is not first in `$PATH`.
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## chruby
|
2014-02-02 04:37:29 +00:00
|
|
|
|
2021-05-05 17:59:01 +00:00
|
|
|
Yet another alternative is [_chruby_][4], which is simpler than both _rvm_ and
|
|
|
|
_rbenv_.
|
2014-02-02 04:37:29 +00:00
|
|
|
|
|
|
|
### Settings
|
|
|
|
|
|
|
|
#### Auto-Switch
|
|
|
|
|
|
|
|
To enable auto switching the Ruby version on directory change based on the
|
2021-05-05 17:59:01 +00:00
|
|
|
`.ruby-version` file, add the following line to _`${ZDOTDIR:-$HOME}/.zpreztorc`_:
|
2014-02-02 04:37:29 +00:00
|
|
|
|
2017-07-21 01:07:29 +00:00
|
|
|
```sh
|
|
|
|
zstyle ':prezto:module:ruby:chruby' auto-switch 'yes'
|
|
|
|
```
|
2014-02-02 04:37:29 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Bundler
|
2012-06-13 01:02:14 +00:00
|
|
|
|
|
|
|
Manage gems that are not meant to be used as commands, such as application
|
2021-05-04 01:59:31 +00:00
|
|
|
dependencies, with [Bundler][5].
|
2012-06-13 01:02:14 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Aliases
|
2012-06-13 01:02:14 +00:00
|
|
|
|
2012-08-15 01:10:12 +00:00
|
|
|
### General
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
- `rb` is short for `ruby`.
|
2012-08-15 01:10:12 +00:00
|
|
|
|
2012-06-13 01:02:14 +00:00
|
|
|
### Bundler
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
- `rbb` manages ruby dependencies (`bundle`).
|
|
|
|
- `rbbc` cleans up unused gems in your bundler directory.
|
|
|
|
- `rbbe` executes a script in the context of the current bundle.
|
|
|
|
- `rbbi` installs the gems specified in the `Gemfile` in `vendor/bundle`.
|
|
|
|
- `rbbI` installs the following:
|
|
|
|
- gems specified in the `Gemfile` in `vendor/bundle`.
|
|
|
|
- packages the gems into `vendor/cache`.
|
2021-05-05 17:59:01 +00:00
|
|
|
- appends bundler directories to `.gitignore`.
|
2021-05-04 01:59:31 +00:00
|
|
|
- `rbbl` lists all gems in the current bundle.
|
|
|
|
- `rbbo` opens an installed gem in the editor.
|
|
|
|
- `rbbp` packages gem files into `vendor/cache`.
|
|
|
|
- `rbbu` updates gems to their latest version.
|
|
|
|
|
|
|
|
## Functions
|
|
|
|
|
|
|
|
- `ruby-app-root` displays the path to the Ruby application root directory.
|
|
|
|
- `ruby-info` exposes information about the Ruby environment via the
|
|
|
|
`$ruby_info` associative array.
|
|
|
|
|
|
|
|
## Theming
|
2012-09-07 03:06:50 +00:00
|
|
|
|
|
|
|
To display the name of the current Ruby version in a prompt, define the
|
2012-10-02 16:53:59 +00:00
|
|
|
following style in the `prompt_name_setup` function.
|
2012-09-07 03:06:50 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
```sh
|
|
|
|
# %v - ruby version.
|
|
|
|
zstyle ':prezto:module:ruby:info:version' format 'version:%v'
|
|
|
|
```
|
2012-09-07 03:06:50 +00:00
|
|
|
|
|
|
|
Then add `$ruby_info[version]` to `$PROMPT` or `$RPROMPT` and call
|
2012-10-02 16:53:59 +00:00
|
|
|
`ruby-info` in the `prompt_name_preexec` hook function.
|
2012-09-07 03:06:50 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Authors
|
2012-06-13 01:02:14 +00:00
|
|
|
|
2021-05-05 17:59:01 +00:00
|
|
|
_The authors of this module should be contacted via the [issue tracker][6]._
|
2012-06-13 01:02:14 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
- [Sorin Ionescu](https://github.com/sorin-ionescu)
|
2012-06-13 01:02:14 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
[1]: https://www.ruby-lang.org
|
2021-05-17 06:24:03 +00:00
|
|
|
[2]: https://github.com/rbenv/rbenv
|
|
|
|
[3]: https://rvm.io
|
2017-08-29 23:40:17 +00:00
|
|
|
[4]: https://github.com/postmodern/chruby
|
2021-05-04 01:59:31 +00:00
|
|
|
[5]: https://gembundler.com
|
|
|
|
[6]: https://github.com/sorin-ionescu/prezto/issues
|