LoginSignup
0
0

More than 5 years have passed since last update.

irbでソースコードフォルダ毎に履歴を分けて保存する

Last updated at Posted at 2017-10-08

irb(Rails console含む)では、履歴を保存・参照することができますが、ソースコードフォルダ毎に分けて利用できた方が便利なシーンも多いので作ってみました。

と言ってもやっていることは単純で、カレントディレクトリをキーにして、履歴ファイルを設定しているだけです。

以下を ~/.irbrc に記載します。履歴ファイルは ~/.irb/histories フォルダに置くようにしていますが、適当に別なフォルダを指定しても問題ありません。

require 'irb/ext/save-history'

IRB.conf[:SAVE_HISTORY] = 80000 # このあたりはお好みで。

require 'digest/md5'
require 'fileutils'
history_base = File.join(ENV['HOME'], '.irb', 'histories')
FileUtils.mkdir_p history_base unless Dir.exist? history_base
pwd_hash = Digest::MD5.hexdigest(`pwd`.chomp)
IRB.conf[:HISTORY_FILE] = File.join(history_base, pwd_hash)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0