Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ Metrics/ClassLength:

Metrics/MethodLength:
Max: 20

# ======== Style ===========
Style/FrozenStringLiteralComment:
Exclude:
- 'examples/.irbrc'
56 changes: 46 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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`)
Expand Down
58 changes: 47 additions & 11 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` を使用)
Expand Down
26 changes: 26 additions & 0 deletions examples/.irbrc
Original file line number Diff line number Diff line change
@@ -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