From 340c74e618548eeb661bff56c386caeafdef6023 Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Mon, 19 Jan 2026 21:29:40 +0900 Subject: [PATCH 1/2] Add .irbrc example and update README for Bundler compatibility --- README.md | 56 ++++++++++++++++++++++++++++++++++++++--------- README_ja.md | 58 +++++++++++++++++++++++++++++++++++++++---------- examples/.irbrc | 26 ++++++++++++++++++++++ 3 files changed, 119 insertions(+), 21 deletions(-) create mode 100644 examples/.irbrc diff --git a/README.md b/README.md index 8ef6ae2..b1fdee2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # RelinePac - Reline extensions for completion, history search, and clipboard helpers with simple keybind configuration for IRB/pry. English | [日本語](README_ja.md) @@ -10,29 +9,66 @@ English | [日本語](README_ja.md) - macOS `pbcopy`/`pbpaste` commands (for clipboard operations) ## Installation -- After publishing to RubyGems: add `gem "reline_pac"` to your Gemfile. -- From this repository while developing: `bundle exec rake install`. -## Usage -Call `RelinePac.configure` during IRB/pry startup (e.g., `~/.irbrc`) and bind keys to `Reline::LineEditor` methods. +Install the gem globally (not in your project's Gemfile): + +```bash +gem install reline_pac +``` + +Then add the following to your `~/.irbrc`. This works even in Bundler environments (like `rails console`): ```ruby -# ~/.irbrc +# Check if running in a Bundler environment (e.g., rails c) +if defined?(Bundler) + # Temporarily unbundle to get the system gem path + reline_pac_gem_path = Bundler.with_unbundled_env do + `gem which reline_pac 2> /dev/null`.chomp + end + + unless reline_pac_gem_path.empty? + lib_dir = File.dirname(reline_pac_gem_path) + $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) + end +end + begin - require "reline_pac" + require 'reline_pac' RelinePac.configure do |config| + # Apply default keybindings RelinePac::Packages::DEFAULT_KEYBINDS.each do |key, method| config.add_keybind(key, method) end - - # override or add your own bindings - # config.add_keybind("\C-r", :fzf_history) end + # You can override or add custom keybindings + # config.add_keybind("\C-r", :fzf_history) rescue LoadError # do nothing end ``` +Alternatively, you can download it directly from GitHub: + +```bash +curl -o ~/.irbrc https://raw.githubusercontent.com/Syati/reline_pac/main/examples/.irbrc +``` + +## Usage + +Add the setup code from the Installation section to your `~/.irbrc` to enable default keybindings. + +### Custom packages +You can add your own custom methods: + +```ruby +RelinePac.configure do |config| + config.add_package(:my_custom_method) do |_key| + insert_text("Hello from custom package!") + end + config.add_keybind("\C-x", :my_custom_method) +end +``` + ### Default keybinds - `\C-y` -> `:pbpaste` (uses macOS `pbpaste`) - `\C-k` -> `:pbcopy_kill` (uses macOS `pbcopy`) diff --git a/README_ja.md b/README_ja.md index c50725e..ee37dd6 100644 --- a/README_ja.md +++ b/README_ja.md @@ -9,30 +9,66 @@ IRB や pry 向けに、補完・履歴検索・クリップボードを拡張 - macOS の `pbcopy`/`pbpaste` コマンド(クリップボード操作に必要) ## インストール -- RubyGems 公開後: Gemfile に `gem "reline_pac"` を追加します。 -- リポジトリから開発インストール: `bundle exec rake install`。 -## 使い方 -IRB や pry の起動時(例: `~/.irbrc`)に `RelinePac.configure` を呼び出し、`Reline::LineEditor` のメソッドへキーを割り当てます。 +gem をグローバルにインストールします(プロジェクトの Gemfile には追加しません): + +```bash +gem install reline_pac +``` + +次に `~/.irbrc` に以下を追加します。Bundler 環境(`rails console` など)でも動作します: ```ruby -# ~/.irbrc +# Check if running in a Bundler environment (e.g., rails c) +if defined?(Bundler) + # Temporarily unbundle to get the system gem path + reline_pac_gem_path = Bundler.with_unbundled_env do + `gem which reline_pac 2> /dev/null`.chomp + end + + unless reline_pac_gem_path.empty? + lib_dir = File.dirname(reline_pac_gem_path) + $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) + end +end + begin - require "reline_pac" + require 'reline_pac' RelinePac.configure do |config| - # デフォルトを適用 + # Apply default keybindings RelinePac::Packages::DEFAULT_KEYBINDS.each do |key, method| config.add_keybind(key, method) end - - # 上書きや独自の割り当ても可能 - # config.add_keybind("\C-r", :fzf_history) - end + end + # You can override or add custom keybindings + # config.add_keybind("\C-r", :fzf_history) rescue LoadError # do nothing end ``` +または、GitHub から直接ダウンロードすることもできます: + +```bash +curl -o ~/.irbrc https://raw.githubusercontent.com/Syati/reline_pac/main/examples/.irbrc +``` + +## 使い方 + +インストールセクションの設定例を `~/.irbrc` に追加すれば、デフォルトのキーバインドが利用できます。 + +### カスタムパッケージ +独自のメソッドを追加できます: + +```ruby +RelinePac.configure do |config| + config.add_package(:my_custom_method) do |_key| + insert_text("Hello from custom package!") + end + config.add_keybind("\C-x", :my_custom_method) +end +``` + ### デフォルトのキー割り当て - `\C-y` -> `:pbpaste`(macOS の `pbpaste` を使用) - `\C-k` -> `:pbcopy_kill`(macOS の `pbcopy` を使用) diff --git a/examples/.irbrc b/examples/.irbrc new file mode 100644 index 0000000..62680cd --- /dev/null +++ b/examples/.irbrc @@ -0,0 +1,26 @@ +# Check if running in a Bundler environment (e.g., rails c) +if defined?(Bundler) + # Temporarily unbundle to get the system gem path + reline_pac_gem_path = Bundler.with_unbundled_env do + `gem which reline_pac 2> /dev/null`.chomp + end + + unless reline_pac_gem_path.empty? + lib_dir = File.dirname(reline_pac_gem_path) + $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) + end +end + +begin + require 'reline_pac' + RelinePac.configure do |config| + # Apply default keybindings + RelinePac::Packages::DEFAULT_KEYBINDS.each do |key, method| + config.add_keybind(key, method) + end + end + # You can override or add custom keybindings + # config.add_keybind("\C-r", :fzf_history) +rescue LoadError + # do nothing +end From f4d852ea6fbf0a28ffaf5031a695a248f570054c Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Mon, 19 Jan 2026 21:34:03 +0900 Subject: [PATCH 2/2] Exclude examples/.irbrc from Style/FrozenStringLiteralComment in .rubocop.yml --- .rubocop.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index aee28f6..5d503ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -27,3 +27,8 @@ Metrics/ClassLength: Metrics/MethodLength: Max: 20 + +# ======== Style =========== +Style/FrozenStringLiteralComment: + Exclude: + - 'examples/.irbrc'