DRYな備忘録

Don't Repeat Yourself.

Rubyも何も入ってないところからrakを使うまでのインストールメモ【rak】【gem】【rvm】【Ruby】

f:id:otiai10:20140616110227p:plain

rakっていうコマンド便利ですよ

問題

% rak invalid
zsh: command not found: rak
% which gem
gem not found
% which ruby
ruby not found
%

Σ(゚д゚lll)ファ!?

Rubyから入れましょう

1) rvmでRuby2.0.0を入れる

% cat /etc/debian_version
7.5
% curl -sSL https://get.rvm.io | bash -s stable --ruby=2.0.0
Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz

Installing RVM to /home/otiai10/.rvm/
    Adding rvm PATH line to /home/otiai10/.profile /home/otiai10/.bashrc /home/otiai10/.zshrc.
    Adding rvm loading line to /home/otiai10/.bash_profile /home/otiai10/.zlogin.
Installation of RVM in /home/otiai10/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/otiai10/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# otiai10,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: http://rvm.io/help and https://twitter.com/rvm_io

  * WARNING: /usr/bin/zsh version 4.3.17 detected - Zsh 4.3.12 / 5.0.0+ is recommended,
    with current one errors to be expected - bugs in shell code interpretation.

# 〜〜中略〜〜

  * To start using RVM you need to run `source /home/otiai10/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
  * To start using RVM you need to run `source /home/otiai10/.rvm/scripts/rvm`

とあるのでまあその通りに

% which ruby
ruby not found
% source /home/otiai10/.rvm/scripts/rvm
[反応無し]
% which ruby
/home/otiai10/.rvm/rubies/ruby-2.0.0-p481/bin/ruby

ちなみに

% which gem
gem () {
    typeset result
    (
        typeset rvmrc
        rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
        if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
        then
            rvm_rvmrc_files+=("${rvm_prefix}/.rvmrc")
        fi
        for rvmrc in "${rvm_rvmrc_files[@]}"
        do
            [[ -s "${rvmrc}" ]] && source "${rvmrc}" || true
        done
        unset rvm_rvmrc_files
        command gem "$@"
    ) || result=$?
    hash -r
    return ${result:-0}
}
%

gemもある。

2) gemを使ってrakを入れる

とりあえずruby2.0.0環境だけでいいでしょう

% gem install rak
Fetching: rak-1.4.gem (100%)
Successfully installed rak-1.4
Parsing documentation for rak-1.4
Installing ri documentation for rak-1.4
1 gem installed
% which rak
/home/otiai10/.rvm/gems/ruby-2.0.0-p481/bin/rak

入った

3) rak使ってみる

rakはgrepよりラク。

  • 勝手に色づけ
  • デフォルトでカレントディレクトリからrecursiveに検索
  • など?

f:id:otiai10:20140616105349p:plain

こういう感じ

4) rakで検索できるファイル拡張子を追加

Ruby2.0.0下で入れたgemはここ~/.rvm/gems/ruby-2.0.0-p481/gems/にあるので、

% cp ~/.rvm/gems/ruby-2.0.0-p481/gems/rak-1.4/bin/rak ~/.rvm/gems/ruby-2.0.0-p481/gems/rak-1.4/bin/rak.backup
% vi ~/.rvm/gems/ruby-2.0.0-p481/gems/rak-1.4/bin/rak

diff -u ~/.rvm/gems/ruby-2.0.0-p481/gems/rak-1.4/bin/rak.backup ~/.rvm/gems/ruby-2.0.0-p481/gems/rak-1.4/bin/rak

--- /home/otiai10/.rvm/gems/ruby-2.0.0-p481/gems/rak-1.4/bin/rak.backup  2014-06-16 10:58:18.691816001 +0900
+++ /home/otiai10/.rvm/gems/ruby-2.0.0-p481/gems/rak-1.4/bin/rak  2014-06-16 10:59:44.343816001 +0900
@@ -61,11 +61,12 @@
     :elisp         => %w( .el ),
     :erlang        => %w( .erl .hrl ),
     :fortran       => %w( .f .f03 .f77 .f90 .f95 .for .fpp .ftn ),
+    :go            => %w( .go ),
     :haskell       => %w( .hs .lhs ),
     :hh            => %w( .h ),
     :html          => %w( .htm .html .shtml .xhtml ),
     :java          => %w( .java .properties properties ),
-    :js            => %w( .js ),
+    :js            => %w( .js .ts .coffee),
     :jsp           => %w( .jhtm .jhtml .jsp .jspx ),
     :lisp          => %w( .lisp .lsp ),
     :lua           => %w( .lua ),

こうしとくと、

f:id:otiai10:20140616110227p:plain

こうなります。ちゃんと.goなファイルも検索できてる。

ラクです。