rufio 0.41.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a8696f2d93276e424c2cad84cb869547858bd7f9e97ab40405838d92640c3d6
4
- data.tar.gz: 517baff63dd16d5943a4d7aea0c5141d56041077a0f83a8525daa269f8b442f3
3
+ metadata.gz: d3c498939bce28d320a22b6c702a489a2104735703ba4510ad6e81457451f9b5
4
+ data.tar.gz: 16b83c1e9046f78ffe672f4cf7dcfcbfc9a1e4bcde1d2928dcfaab48e9f33cfe
5
5
  SHA512:
6
- metadata.gz: ccf7de9709e26faa8452140ef00c4daa9a4e5f8e3725b30e1970f202ec51301975a2feb5dbe197fb04aea50fa6006f4e002996b27209847afdff2d1b046bb253
7
- data.tar.gz: d74bc18839a9c460bf13c4e937399d3de9027d2eb9c712a6131e5c31c3881a4cce8488ab0209876d5ebb16917abbc37fac9c2aed743c6b0646b616b30cbc5d4d
6
+ metadata.gz: 1a50608548e316135b5de39fa2b974cdf95682c80656153a96bf450d65c833967bdea84f3597eee7c1bb049f2daf4791ed60ab926400f7a54dbfaafd14753ae4
7
+ data.tar.gz: b4bb9b1e61ec2594a039e43c17e1d4d3d90f91ef382161ac7cb2df75e7b37f301e1312e4b6456af6c91941553a11119db11b0d1d415d42142785c13166bf13c0
data/README.md CHANGED
@@ -6,7 +6,7 @@ Ruby製のターミナルベースファイルマネージャー
6
6
 
7
7
  ## 概要
8
8
 
9
- rufioは、Yaziにインスパイアされたターミナル上で動作するファイルマネージャーです。Rubyで実装されており、プラグインサポートを備えています。軽量で高速な操作性を提供し、ファイルの閲覧・管理・検索機能を備えています。
9
+ rufioは、Yaziにインスパイアされたターミナル上で動作するファイルマネージャーです。Rubyで実装されており、DSLコマンドによる拡張機能を備えています。軽量で高速な操作性を提供し、ファイルの閲覧・管理・検索機能を備えています。
10
10
 
11
11
  ### 🚀 v0.33.0の重要な更新
12
12
 
@@ -20,12 +20,12 @@ rufioは、Yaziにインスパイアされたターミナル上で動作する
20
20
 
21
21
  - **軽量でシンプル**: Rubyで書かれた軽量なファイルマネージャー
22
22
  - **直感的な操作**: Vimライクなキーバインド
23
- - **プラグインシステム**: 拡張可能なプラグインアーキテクチャ
23
+ - **DSLコマンドシステム** (v0.50.0): 拡張可能なDSLベースのコマンド定義
24
24
  - **強力なコマンドモード** (v0.32.0):
25
25
  - シェルコマンド実行 (`!ls`, `!git status` など)
26
26
  - コマンド履歴(上下矢印キーでナビゲーション)
27
27
  - インテリジェントなTab補完(候補リスト表示)
28
- - Rubyプラグインによる拡張可能なコマンド
28
+ - DSLコマンドによる拡張可能なコマンド
29
29
  - **バックグラウンドコマンド実行** (v0.33.0):
30
30
  - `:!command` でシェルコマンドを非同期実行
31
31
  - 実行中もrufioの操作が可能
@@ -249,9 +249,10 @@ rufio --help # ヘルプメッセージを表示
249
249
  - 完了時に通知メッセージを3秒間表示
250
250
  - 実行結果は自動的に `~/.config/rufio/log/` に保存
251
251
 
252
- **Rubyコマンド** (v0.32.0):
252
+ **DSLコマンド** (v0.50.0):
253
253
  ```
254
- :hello # Hello プラグインを実行
254
+ :hello # Hello DSLコマンドを実行
255
+ :stop # rufioを終了
255
256
  ```
256
257
 
257
258
  #### ログビューワ (v0.33.0)
@@ -507,7 +508,7 @@ apt install zoxide
507
508
 
508
509
  #### 利用可能なコマンド
509
510
 
510
- コマンドはプラグインによって提供されます。プラグインシステムの詳細については後述の「プラグインシステム」セクションを参照してください。
511
+ コマンドはDSLで定義されます。DSLコマンドシステムの詳細については後述の「DSLコマンドシステム」セクションを参照してください。
511
512
 
512
513
  ### 必要な外部ツール
513
514
 
@@ -589,188 +590,93 @@ COLORS = {
589
590
  - `selected`: 選択中の項目の色
590
591
  - `preview`: プレビューパネルの色
591
592
 
592
- ## プラグインシステム
593
+ ## DSLコマンドシステム
593
594
 
594
- rufioは拡張可能なプラグインシステムを備えており、独自の機能を簡単に追加できます。
595
+ rufioはDSLベースのコマンドシステムを備えており、独自のコマンドを簡単に追加できます。
595
596
 
596
- ### プラグインの配置場所
597
+ ### コマンド定義ファイル
597
598
 
598
- #### 1. 本体同梱プラグイン
599
- ```
600
- lib/rufio/plugins/*.rb
601
- ```
602
- rufioに標準で含まれるプラグイン。外部gem依存なしの基本機能を提供。
599
+ ユーザー定義コマンドは以下のファイルに記述します:
603
600
 
604
- #### 2. ユーザープラグイン
605
601
  ```
606
- ~/.rufio/plugins/*.rb
602
+ ~/.config/rufio/commands.rb
607
603
  ```
608
- ユーザーが自由に追加できるプラグイン。GitHub GistやrawURLから取得可能。
609
604
 
610
- ### プラグインの作成方法
605
+ ### コマンドの作成方法
611
606
 
612
- #### シンプルなプラグイン例
607
+ #### Rubyコードを実行するコマンド
613
608
 
614
609
  ```ruby
615
- # ~/.rufio/plugins/hello.rb
616
- module Rufio
617
- module Plugins
618
- class Hello < Plugin
619
- def name
620
- 'Hello'
621
- end
622
-
623
- def description
624
- 'シンプルな挨拶プラグイン'
625
- end
626
-
627
- def commands
628
- {
629
- hello: method(:say_hello)
630
- }
631
- end
632
-
633
- private
634
-
635
- def say_hello
636
- "Hello from rufio!"
637
- end
638
- end
639
- end
610
+ # ~/.config/rufio/commands.rb
611
+ command "hello" do
612
+ ruby { "Hello from rufio!" }
613
+ description "挨拶コマンド"
640
614
  end
641
- ```
642
-
643
- **プラグインの使い方:**
644
-
645
- 1. rufioを起動
646
- 2. `:`キーでコマンドモードを起動
647
- 3. `hello`と入力(または`he`と入力してTabキーで補完)
648
- 4. Enterキーで実行
649
- 5. フローティングウィンドウに"Hello from rufio!"が表示される
650
615
 
651
- #### 外部gemに依存するプラグイン例
652
-
653
- ```ruby
654
- # ~/.rufio/plugins/ai_helper.rb
655
- module Rufio
656
- module Plugins
657
- class AiHelper < Plugin
658
- requires 'anthropic' # 依存gem宣言
659
-
660
- def name
661
- 'AiHelper'
662
- end
663
-
664
- def description
665
- 'Claude APIを使ったAIアシスタント'
666
- end
667
-
668
- def commands
669
- {
670
- ai: method(:ask_ai)
671
- }
672
- end
673
-
674
- def initialize
675
- super # 依存チェック実行
676
- @client = Anthropic::Client.new(
677
- api_key: ENV['ANTHROPIC_API_KEY']
678
- )
679
- end
680
-
681
- private
682
-
683
- def ask_ai
684
- response = @client.messages.create(
685
- model: "claude-3-5-sonnet-20241022",
686
- max_tokens: 1024,
687
- messages: [{role: "user", content: "Hello, Claude!"}]
688
- )
689
- response.content.first.text
690
- end
691
- end
692
- end
616
+ command "time" do
617
+ ruby { Time.now.strftime("%Y-%m-%d %H:%M:%S") }
618
+ description "現在時刻を表示"
693
619
  end
694
620
  ```
695
621
 
696
- **プラグインの使い方:**
697
-
698
- 1. 依存gemをインストール: `gem install anthropic`
699
- 2. 環境変数を設定: `export ANTHROPIC_API_KEY=your_api_key`
700
- 3. rufioを起動
701
- 4. `:`キーでコマンドモードを起動
702
- 5. `ai`と入力してEnterキーで実行
703
- 6. フローティングウィンドウにClaude APIからの応答が表示される
704
-
705
- ### プラグインの管理
622
+ #### シェルコマンドを実行するコマンド
706
623
 
707
- #### プラグインの有効/無効設定
708
-
709
- `~/.rufio/config.yml`でプラグインの有効/無効を制御できます:
624
+ ```ruby
625
+ command "status" do
626
+ shell "git status"
627
+ description "Gitステータスを表示"
628
+ end
710
629
 
711
- ```yaml
712
- plugins:
713
- fileoperations:
714
- enabled: true
715
- ai_helper:
716
- enabled: true
717
- my_custom:
718
- enabled: false
630
+ command "disk" do
631
+ shell "df -h"
632
+ description "ディスク使用量を表示"
633
+ end
719
634
  ```
720
635
 
721
- #### デフォルト動作
722
-
723
- - `config.yml`が存在しない → 全プラグイン有効
724
- - プラグインの設定がない → 有効とみなす
725
- - `enabled: false`が明示的に設定されている → 無効
726
-
727
- ### プラグインの配布方法
728
-
729
- #### GitHub Gistで共有
636
+ #### 外部スクリプトを実行するコマンド
730
637
 
731
- ```bash
732
- # プラグイン作者
733
- 1. GitHub Gistに.rbファイルをアップロード
734
- 2. Raw URLをユーザーに共有
735
-
736
- # ユーザー
737
- $ mkdir -p ~/.rufio/plugins
738
- $ curl -o ~/.rufio/plugins/my_plugin.rb [RAW_URL]
739
- $ rufio
740
- ✓ my_plugin 読み込み完了
638
+ ```ruby
639
+ command "build" do
640
+ script "~/.config/rufio/scripts/build.rb"
641
+ description "プロジェクトをビルド"
642
+ end
741
643
  ```
742
644
 
743
- #### GitHubリポジトリで共有
645
+ ### コマンドの使い方
744
646
 
745
- ```bash
746
- # プラグイン作者
747
- rufio-plugins/
748
- ├── plugin1.rb
749
- └── plugin2.rb
750
-
751
- # ユーザー
752
- $ curl -o ~/.rufio/plugins/plugin1.rb https://raw.githubusercontent.com/user/rufio-plugins/main/plugin1.rb
753
- ```
647
+ 1. rufioを起動
648
+ 2. `:`キーでコマンドモードを起動
649
+ 3. コマンド名を入力(または一部を入力してTabキーで補完)
650
+ 4. Enterキーで実行
651
+ 5. フローティングウィンドウに結果が表示される
754
652
 
755
- ### プラグインの主要機能
653
+ ### 組み込みコマンド
756
654
 
757
- #### 必須メソッド
655
+ rufioには以下のコマンドがデフォルトで組み込まれています:
758
656
 
759
- - `name`: プラグイン名(必須)
760
- - `description`: プラグインの説明(オプション、デフォルト: "")
761
- - `version`: プラグインのバージョン(オプション、デフォルト: "1.0.0")
762
- - `commands`: コマンド定義(オプション、デフォルト: {})
657
+ | コマンド | 説明 |
658
+ | -------- | ---- |
659
+ | `hello` | 挨拶メッセージを表示 |
660
+ | `stop` | rufioを終了 |
661
+ | `touch` | ファイルを作成 |
662
+ | `mkdir` | ディレクトリを作成 |
763
663
 
764
- #### 依存gem管理
664
+ ### DSLコマンドの種類
765
665
 
766
- - `requires 'gem_name'`: 依存gemを宣言
767
- - 依存gemが不足している場合、警告を表示してプラグインを無効化
768
- - rufio本体は正常に起動継続
666
+ 1. **ruby**: Rubyコードをインラインで実行
667
+ 2. **shell**: シェルコマンドを実行
668
+ 3. **script**: 外部スクリプトファイルを実行
769
669
 
770
- #### 自動登録機能
670
+ ### 設定ファイル構成
771
671
 
772
- - `Plugin`クラスを継承すると自動的に`PluginManager`に登録
773
- - 複雑な登録処理は不要
672
+ ```
673
+ ~/.config/rufio/
674
+ ├── config.rb # カラー設定
675
+ ├── commands.rb # DSLコマンド定義
676
+ ├── bookmarks.json # ブックマーク
677
+ ├── scripts/ # スクリプトファイル
678
+ └── log/ # 実行ログ
679
+ ```
774
680
 
775
681
  ## 開発
776
682
 
data/bin/rufio CHANGED
@@ -3,9 +3,6 @@
3
3
 
4
4
  require_relative '../lib/rufio'
5
5
 
6
- # プラグインを読み込む
7
- Rufio::PluginManager.load_all
8
-
9
6
  # YJITを早期に有効化(引数をチェック)
10
7
  if ARGV.include?('--yjit') && defined?(RubyVM::YJIT)
11
8
  RubyVM::YJIT.enable
@@ -0,0 +1,128 @@
1
+ # CHANGELOG v0.50.0
2
+
3
+ ## 概要
4
+
5
+ DSLコマンドシステムへの完全移行を完了し、旧Pluginシステムを廃止しました。
6
+
7
+ ## 重要な変更
8
+
9
+ ### DSLコマンドシステムへの統一
10
+
11
+ - **Pluginシステムの廃止**: 旧来のPluginベースのコマンドシステムを完全に削除
12
+ - **DSLコマンドへの一本化**: すべてのコマンドがDSLベースで定義可能に
13
+ - **組み込みコマンドのDSL化**: `hello`, `stop`, `touch`, `mkdir` などがDSLコマンドとして実装
14
+
15
+ ### 削除されたファイル
16
+
17
+ #### ライブラリ
18
+ - `lib/rufio/plugin.rb`
19
+ - `lib/rufio/plugin_manager.rb`
20
+ - `lib/rufio/plugin_config.rb`
21
+ - `lib/rufio/plugins/` ディレクトリ
22
+
23
+ #### テスト
24
+ - `test/test_plugin.rb`
25
+ - `test/test_plugin_config.rb`
26
+ - `test/test_plugin_manager.rb`
27
+ - `test/test_plugins_hello.rb`
28
+ - `test/test_plugins_file_operations.rb`
29
+
30
+ ### 新しいDSLコマンドシステム
31
+
32
+ #### コマンド定義ファイル
33
+
34
+ ```ruby
35
+ # ~/.config/rufio/commands.rb
36
+ command "hello" do
37
+ ruby { "Hello from rufio!" }
38
+ description "挨拶コマンド"
39
+ end
40
+
41
+ command "greet" do
42
+ shell "echo 'Hello, World!'"
43
+ description "シェルコマンドで挨拶"
44
+ end
45
+
46
+ command "build" do
47
+ script "~/.config/rufio/scripts/build.rb"
48
+ description "プロジェクトをビルド"
49
+ end
50
+ ```
51
+
52
+ #### DSLコマンドの種類
53
+
54
+ 1. **ruby**: Rubyコードをインラインで実行
55
+ 2. **shell**: シェルコマンドを実行
56
+ 3. **script**: 外部スクリプトファイルを実行
57
+
58
+ #### 組み込みコマンド
59
+
60
+ 以下のコマンドがデフォルトで利用可能:
61
+
62
+ - `hello` - 挨拶メッセージを表示
63
+ - `stop` - rufioを終了
64
+ - `touch` - ファイルを作成
65
+ - `mkdir` - ディレクトリを作成
66
+
67
+ ### 移行ガイド
68
+
69
+ #### 旧Pluginからの移行
70
+
71
+ **旧Plugin形式:**
72
+ ```ruby
73
+ module Rufio
74
+ module Plugins
75
+ class Hello < Plugin
76
+ def commands
77
+ { hello: method(:say_hello) }
78
+ end
79
+
80
+ def say_hello
81
+ "Hello from rufio!"
82
+ end
83
+ end
84
+ end
85
+ end
86
+ ```
87
+
88
+ **新DSL形式:**
89
+ ```ruby
90
+ # ~/.config/rufio/commands.rb
91
+ command "hello" do
92
+ ruby { "Hello from rufio!" }
93
+ description "挨拶コマンド"
94
+ end
95
+ ```
96
+
97
+ ### 破壊的変更
98
+
99
+ - `Rufio::Plugin` クラスは削除されました
100
+ - `Rufio::PluginManager` クラスは削除されました
101
+ - `Rufio::PluginConfig` クラスは削除されました
102
+ - `~/.rufio/plugins/` ディレクトリのプラグインは読み込まれなくなりました
103
+ - `~/.rufio/config.yml` のplugins設定は無視されます
104
+
105
+ ### 設定ファイルの変更
106
+
107
+ #### 新しい設定ファイル構成
108
+
109
+ ```
110
+ ~/.config/rufio/
111
+ ├── config.rb # カラー設定
112
+ ├── commands.rb # DSLコマンド定義(新規)
113
+ ├── bookmarks.json # ブックマーク
114
+ ├── scripts/ # スクリプトファイル
115
+ └── log/ # 実行ログ
116
+ ```
117
+
118
+ ## テスト
119
+
120
+ 全105テストがパス:
121
+ - `test_dsl_command.rb` - 14 tests
122
+ - `test_dsl_command_loader.rb` - 13 tests
123
+ - `test_dsl_command_inline.rb` - 18 tests
124
+ - `test_builtin_commands.rb` - 10 tests
125
+ - `test_command_mode.rb` - 19 tests
126
+ - `test_command_mode_unified.rb` - 11 tests
127
+ - `test_script_executor.rb` - 12 tests
128
+ - `test_dsl_integration.rb` - 8 tests
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rufio
4
+ # 組み込みコマンドを定義するモジュール
5
+ # DSL形式で定義されたコマンドをDslCommandインスタンスとして提供する
6
+ module BuiltinCommands
7
+ class << self
8
+ # 組み込みコマンドをロードする
9
+ # @return [Hash{Symbol => DslCommand}] コマンド名をキーとしたハッシュ
10
+ def load
11
+ commands = {}
12
+
13
+ # hello コマンド
14
+ commands[:hello] = DslCommand.new(
15
+ name: "hello",
16
+ ruby_block: -> { "Hello, World!\n\nこのコマンドはDSLで定義されています。" },
17
+ description: "挨拶メッセージを返す"
18
+ )
19
+
20
+ # stop コマンド
21
+ commands[:stop] = DslCommand.new(
22
+ name: "stop",
23
+ ruby_block: lambda {
24
+ sleep 5
25
+ "done"
26
+ },
27
+ description: "5秒待機してdoneを返す"
28
+ )
29
+
30
+ commands
31
+ end
32
+ end
33
+ end
34
+ end
@@ -3,14 +3,16 @@
3
3
  require 'open3'
4
4
 
5
5
  module Rufio
6
- # コマンドモード - プラグインコマンドを実行するためのインターフェース
6
+ # コマンドモード - DSLコマンドを実行するための統一インターフェース
7
+ # すべてのコマンドはDslCommandとして扱われる
7
8
  class CommandMode
8
9
  attr_accessor :background_executor
9
10
 
10
11
  def initialize(background_executor = nil)
11
12
  @commands = {}
12
13
  @background_executor = background_executor
13
- load_plugin_commands
14
+ load_builtin_commands
15
+ load_dsl_commands
14
16
  end
15
17
 
16
18
  # コマンドを実行する
@@ -38,32 +40,14 @@ module Rufio
38
40
  # コマンド名を取得 (前後の空白を削除)
39
41
  command_name = command_string.strip.to_sym
40
42
 
41
- # コマンドが存在するかチェック
42
- unless @commands.key?(command_name)
43
+ # 統一されたコマンドストアから検索
44
+ command = @commands[command_name]
45
+ unless command
43
46
  return "⚠️ コマンドが見つかりません: #{command_name}"
44
47
  end
45
48
 
46
- # バックグラウンドエグゼキュータが利用可能な場合は非同期実行
47
- if @background_executor
48
- command_method = @commands[command_name][:method]
49
- command_display_name = command_name.to_s
50
-
51
- if @background_executor.execute_ruby_async(command_display_name) do
52
- command_method.call
53
- end
54
- return "🔄 バックグラウンドで実行中: #{command_display_name}"
55
- else
56
- return "⚠️ 既にコマンドが実行中です"
57
- end
58
- end
59
-
60
- # バックグラウンドエグゼキュータがない場合は同期実行
61
- begin
62
- command_method = @commands[command_name][:method]
63
- command_method.call
64
- rescue StandardError => e
65
- "⚠️ コマンド実行エラー: #{e.message}"
66
- end
49
+ # 統一された実行パス
50
+ execute_unified_command(command_name, command)
67
51
  end
68
52
 
69
53
  # 利用可能なコマンドのリストを取得
@@ -73,17 +57,72 @@ module Rufio
73
57
 
74
58
  # コマンドの情報を取得
75
59
  def command_info(command_name)
76
- return nil unless @commands.key?(command_name)
60
+ command = @commands[command_name]
61
+ return nil unless command
77
62
 
78
63
  {
79
64
  name: command_name,
80
- plugin: @commands[command_name][:plugin],
81
- description: @commands[command_name][:description]
65
+ plugin: command[:source] || "dsl",
66
+ description: command[:command].description
82
67
  }
83
68
  end
84
69
 
70
+ # DSLコマンドをロードする
71
+ # @param paths [Array<String>, nil] 設定ファイルのパス配列(nilの場合はデフォルトパス)
72
+ def load_dsl_commands(paths = nil)
73
+ loader = DslCommandLoader.new
74
+
75
+ commands = if paths
76
+ loader.load_from_paths(paths)
77
+ else
78
+ loader.load
79
+ end
80
+
81
+ # ユーザーDSLコマンドは既存のコマンドを上書きする(優先度が高い)
82
+ commands.each do |cmd|
83
+ @commands[cmd.name.to_sym] = {
84
+ command: cmd,
85
+ source: "dsl"
86
+ }
87
+ end
88
+ end
89
+
85
90
  private
86
91
 
92
+ # 組み込みコマンドをロードする
93
+ def load_builtin_commands
94
+ builtin = BuiltinCommands.load
95
+ builtin.each do |name, cmd|
96
+ @commands[name] = {
97
+ command: cmd,
98
+ source: "builtin"
99
+ }
100
+ end
101
+ end
102
+
103
+ # 統一されたコマンド実行
104
+ # @param command_name [Symbol] コマンド名
105
+ # @param command [Hash] コマンド情報 { command: DslCommand, source: String }
106
+ # @return [Hash] 実行結果
107
+ def execute_unified_command(command_name, command)
108
+ dsl_cmd = command[:command]
109
+
110
+ # バックグラウンドエグゼキュータが利用可能な場合は非同期実行
111
+ if @background_executor
112
+ command_display_name = command_name.to_s
113
+ if @background_executor.execute_ruby_async(command_display_name) do
114
+ ScriptExecutor.execute_command(dsl_cmd)
115
+ end
116
+ return "🔄 バックグラウンドで実行中: #{command_display_name}"
117
+ else
118
+ return "⚠️ 既にコマンドが実行中です"
119
+ end
120
+ end
121
+
122
+ # 同期実行
123
+ ScriptExecutor.execute_command(dsl_cmd)
124
+ end
125
+
87
126
  # シェルコマンドを実行する
88
127
  def execute_shell_command(shell_command)
89
128
  # コマンドが空の場合
@@ -111,26 +150,5 @@ module Rufio
111
150
  { success: false, error: "コマンド実行エラー: #{e.message}" }
112
151
  end
113
152
  end
114
-
115
- # プラグインからコマンドを読み込む
116
- def load_plugin_commands
117
- # 有効なプラグインを取得
118
- enabled_plugins = PluginManager.enabled_plugins
119
-
120
- # 各プラグインからコマンドを取得
121
- enabled_plugins.each do |plugin|
122
- plugin_name = plugin.name
123
- plugin_commands = plugin.commands
124
-
125
- # 各コマンドを登録
126
- plugin_commands.each do |command_name, command_method|
127
- @commands[command_name] = {
128
- method: command_method,
129
- plugin: plugin_name,
130
- description: plugin.description
131
- }
132
- end
133
- end
134
- end
135
153
  end
136
154
  end