From 94679cea6f3fe57e74abf94df581f363b041521a Mon Sep 17 00:00:00 2001 From: "takemi.ohama" Date: Wed, 13 May 2026 17:52:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat(cli):=20devbase=20shell-rc=20=E3=82=B5?= =?UTF-8?q?=E3=83=96=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `devbase init` が書き込んだ rc ファイルのパスを stdout に 1 行出力する ユーティリティサブコマンド。`source "$(devbase shell-rc)"` のように コマンド置換と組み合わせて使い、ユーザーに環境(zsh / bash on Linux / bash on macOS)の判定を意識させずに rc を再読み込みできるようにする。 ロジックは既存の `get_shell_rc_file()` を再利用。DEVBASE_ROOT は不要。 - lib/devbase/commands/shell.py: 新規(cmd_shell_rc) - lib/devbase/cli.py: subparser 登録、prefix 解決リスト、dispatch (DEVBASE_ROOT 不要グループに配置) - bin/devbase: bash dispatcher の commands 一覧と case 分岐 - etc/devbase-completion.bash: bash 補完 - etc/_devbase: zsh 補完 --- bin/devbase | 4 ++-- etc/_devbase | 1 + etc/devbase-completion.bash | 2 +- lib/devbase/cli.py | 11 ++++++++++- lib/devbase/commands/shell.py | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 lib/devbase/commands/shell.py diff --git a/bin/devbase b/bin/devbase index 4d73dfc..a9aa9cc 100755 --- a/bin/devbase +++ b/bin/devbase @@ -163,7 +163,7 @@ run_python() { # Resolve abbreviated command to full command name via unique prefix matching resolve_command() { local input="$1" - local commands="init status container ct env plugin pl snapshot ss up down login build ps scale help" + local commands="init status shell-rc container ct env plugin pl snapshot ss up down login build ps scale help" local matches=() for cmd in $commands; do [[ "$cmd" == "$input"* ]] && matches+=("$cmd") @@ -186,7 +186,7 @@ case "$_resolved_cmd" in # Python-implemented commands --version|-V) run_python "$@" ;; - init|status|container|ct|env|plugin|pl|snapshot|ss|up|down|login|ps|scale) + init|status|shell-rc|container|ct|env|plugin|pl|snapshot|ss|up|down|login|ps|scale) run_python "${_resolved_cmd}" "${@:2}" ;; # Shell-implemented commands build) shift; cmd_build "$@" ;; diff --git a/etc/_devbase b/etc/_devbase index a705a13..9df7250 100644 --- a/etc/_devbase +++ b/etc/_devbase @@ -38,6 +38,7 @@ _devbase() { commands=( 'init:Initialize devbase environment' 'status:Show overall status' + 'shell-rc:Print shell RC file path (for source ...)' 'container:Manage containers' 'ct:Manage containers (alias)' 'env:Manage environment variables' diff --git a/etc/devbase-completion.bash b/etc/devbase-completion.bash index 33d4445..cc62a91 100644 --- a/etc/devbase-completion.bash +++ b/etc/devbase-completion.bash @@ -10,7 +10,7 @@ _devbase_completions() { cword=$COMP_CWORD } - local commands="init status container ct env plugin pl snapshot ss up down login build ps help" + local commands="init status shell-rc container ct env plugin pl snapshot ss up down login build ps help" local container_subcommands="up down ps login logs scale build" local env_subcommands="init sync list set get delete edit project" local plugin_subcommands="list install uninstall update info sync repo" diff --git a/lib/devbase/cli.py b/lib/devbase/cli.py index b863751..fb600b3 100644 --- a/lib/devbase/cli.py +++ b/lib/devbase/cli.py @@ -236,6 +236,10 @@ def _create_parser(): # --- Top-level commands --- subparsers.add_parser('init', help='Initialize devbase environment') subparsers.add_parser('status', help='Show overall status') + subparsers.add_parser( + 'shell-rc', + help='Print shell RC file path (e.g. source "$(devbase shell-rc)")' + ) _add_container_parser(subparsers) _add_env_parser(subparsers) @@ -258,7 +262,7 @@ def _resolve_prefix(input_cmd, candidates): def _expand_argv(): """Expand abbreviated command/subcommand names in sys.argv in-place.""" - commands = ['init', 'status', 'container', 'ct', 'env', 'plugin', 'pl', + commands = ['init', 'status', 'shell-rc', 'container', 'ct', 'env', 'plugin', 'pl', 'snapshot', 'ss', 'up', 'down', 'login', 'build', 'ps', 'scale', 'help'] repo_subcmds = ['add', 'remove', 'list', 'refresh'] @@ -315,6 +319,11 @@ def _dispatch(cmd, args): from devbase.commands.container import cmd_container return cmd_container(args) + # --- Commands not requiring DEVBASE_ROOT --- + if cmd == 'shell-rc': + from devbase.commands.shell import cmd_shell_rc + return cmd_shell_rc() + # --- Commands requiring DEVBASE_ROOT --- devbase_root = _require_devbase_root() diff --git a/lib/devbase/commands/shell.py b/lib/devbase/commands/shell.py new file mode 100644 index 0000000..64b25c1 --- /dev/null +++ b/lib/devbase/commands/shell.py @@ -0,0 +1,15 @@ +"""Shell-related utility commands""" + +from devbase.utils.shell import get_shell_rc_file + + +def cmd_shell_rc() -> int: + """Print the appropriate shell RC file path to stdout (single line). + + Intended for `source "$(devbase shell-rc)"` so users can reload the + file `devbase init` wrote to without needing to know which one + (zsh -> ~/.zshrc, bash on macOS -> ~/.bash_profile, + bash on Linux -> ~/.bashrc). + """ + print(get_shell_rc_file()) + return 0 From be9a881e6d31d0b160f575ea803c679892804c5f Mon Sep 17 00:00:00 2001 From: "takemi.ohama" Date: Wed, 13 May 2026 18:18:02 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs(shell-rc):=20cli-reference=20/=20READM?= =?UTF-8?q?E=20/=20getting-started=20=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=97?= =?UTF-8?q?=20commands/shell.py=20=E3=82=92=E3=83=AA=E3=83=8D=E3=83=BC?= =?UTF-8?q?=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #11 のレビュー指摘 (Codex) への対応。 - docs/user/cli-reference.md: `devbase shell-rc` セクションを追加。 mermaid 図と環境別出力テーブル、`source "$(...)"` の引用符必須注記を含める。 - README.md: クイックスタートを `source "$(./bin/devbase shell-rc)"` ワンライナーに変更し、`devbase build` 行を削除(`devbase up` が 自動でビルド/pull するため)。トップレベルコマンド一覧に shell-rc 追記。 - docs/user/getting-started.md: Step 3 の bash/zsh ケース分岐を `source "$(./bin/devbase shell-rc)"` に統一。引用符必須の注記を追加。 - lib/devbase/commands/shell.py を shell_rc.py にリネーム。 utils/shell.py との名前衝突による検索・補完時の混乱を回避(Codex N-2)。 --- README.md | 7 +++-- docs/user/cli-reference.md | 27 +++++++++++++++++++ docs/user/getting-started.md | 14 +++++----- lib/devbase/cli.py | 2 +- .../commands/{shell.py => shell_rc.py} | 0 5 files changed, 39 insertions(+), 11 deletions(-) rename lib/devbase/commands/{shell.py => shell_rc.py} (100%) diff --git a/README.md b/README.md index a0dbaa5..9f1cab5 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ devbaseは、Docker Composeを使った再現性の高い開発環境を提供 git clone https://github.com/devbasex/devbase.git cd devbase ./bin/devbase init -source ~/.bashrc # または ~/.zshrc +source "$(./bin/devbase shell-rc)" # rc ファイル(zsh/bash on Linux/macOS)を自動判定して再読み込み # 2. Pluginのインストール devbase plugin repo add user/repo # リポジトリ登録(init でサンプルレジストリ devbasex/devbase-samples は自動登録済み) @@ -32,8 +32,7 @@ devbase plugin install # Plugin名でインストール # 3. プロジェクトの起動 cd projects/your-project devbase env init # 環境変数の設定(初回のみ) -devbase build # コンテナイメージのビルド(初回のみ) -devbase up # コンテナを起動 +devbase up # コンテナを起動(初回はイメージビルドを含むため時間がかかります) devbase login # コンテナにログイン ``` @@ -83,7 +82,7 @@ devbaseのコマンドは4つのグループにまとめられています。 - **ショートカット**: `up`, `down`, `login`, `build`, `ps` はトップレベルから直接使用可能 - **プレフィックス略記**: `devbase p l` → `devbase plugin list` -- **トップレベルコマンド**: `init`, `status` +- **トップレベルコマンド**: `init`, `status`, `shell-rc` 全コマンドの構文・オプション・使用例は [CLIリファレンス](docs/user/cli-reference.md) を参照してください。 diff --git a/docs/user/cli-reference.md b/docs/user/cli-reference.md index 89307aa..74d0bf6 100644 --- a/docs/user/cli-reference.md +++ b/docs/user/cli-reference.md @@ -10,6 +10,7 @@ devbase のコマンドは 4 つのグループとトップレベルコマンド graph TD A[devbase] --> B[init] A --> C[status] + A --> H[shell-rc] A --> D[container / ct] A --> E[env] A --> F[plugin / pl] @@ -86,6 +87,32 @@ devbase status - 環境変数の設定状況 - スナップショットの状態 +### `devbase shell-rc` + +`devbase init` が書き込んだシェル設定ファイル(rc ファイル)のフルパスを stdout に 1 行だけ出力します。`source` のコマンド置換と組み合わせ、ユーザーが zsh / bash on Linux / bash on macOS のどれを使っているかを意識せずに rc ファイルを再読み込みするためのユーティリティです。 + +``` +devbase shell-rc +``` + +判定ロジックは `devbase init` と同一なので、書き込み先と完全に一致します。 + +| 環境 | 出力例 | +|------|--------| +| zsh | `/Users//.zshrc` | +| bash on macOS | `/Users//.bash_profile` | +| bash on Linux | `/home//.bashrc` | + +使用例: + +```bash +# 初期化直後に rc を再読み込み(環境差を吸収) +./bin/devbase init +source "$(./bin/devbase shell-rc)" +``` + +> **⚠ 引用符は必須**: `source $(devbase shell-rc)` のように引用符を省くと、ホームディレクトリ名に空白を含む環境(例: `/Users/foo bar/.zshrc`)で word splitting が起き `source` が失敗します。必ず `source "$(devbase shell-rc)"` の形で書いてください。 + ## container (ct) グループ コンテナのライフサイクル管理を行うコマンド群です。 diff --git a/docs/user/getting-started.md b/docs/user/getting-started.md index 6749110..b2f5cf8 100644 --- a/docs/user/getting-started.md +++ b/docs/user/getting-started.md @@ -34,20 +34,22 @@ cd devbase `init` コマンドは以下を自動実行します。 -- `bin/devbase` を PATH に追加(`~/.bashrc` / `~/.zshrc` に追記) +- `bin/devbase` を PATH に追加(環境に応じて `~/.zshrc` / `~/.bashrc` / `~/.bash_profile` のいずれかに追記) - シェル補完スクリプトの登録(Tab 補完が有効になる) - プラグイン設定ファイル `plugins.yml` の作成 +書き込み先は現在のシェル種別と OS から自動判定されます(zsh → `~/.zshrc`、bash on macOS → `~/.bash_profile`、bash on Linux → `~/.bashrc`)。 + ### 3. シェルの再読み込み ```bash -# Bash の場合 -source ~/.bashrc - -# Zsh の場合 -source ~/.zshrc +source "$(./bin/devbase shell-rc)" ``` +`devbase shell-rc` は `init` が書き込んだ rc ファイルのパスを 1 行で出力します。コマンド置換と組み合わせることで、環境差を意識せずに 1 行で再読み込みできます。 + +> **⚠ 引用符は必須**: `source $(./bin/devbase shell-rc)` のように引用符を省くと、ホームディレクトリ名に空白を含む環境(例: `/Users/foo bar/.zshrc`)で word splitting が起き `source` が失敗します。必ず `source "$(...)"` の形で書いてください。 + > **Note:** 新しいターミナルを開いても同様に反映されます。 ### 4. プラグインリポジトリの登録 diff --git a/lib/devbase/cli.py b/lib/devbase/cli.py index fb600b3..3201679 100644 --- a/lib/devbase/cli.py +++ b/lib/devbase/cli.py @@ -321,7 +321,7 @@ def _dispatch(cmd, args): # --- Commands not requiring DEVBASE_ROOT --- if cmd == 'shell-rc': - from devbase.commands.shell import cmd_shell_rc + from devbase.commands.shell_rc import cmd_shell_rc return cmd_shell_rc() # --- Commands requiring DEVBASE_ROOT --- diff --git a/lib/devbase/commands/shell.py b/lib/devbase/commands/shell_rc.py similarity index 100% rename from lib/devbase/commands/shell.py rename to lib/devbase/commands/shell_rc.py