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
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 は自動登録済み)
Expand All @@ -32,8 +32,7 @@ devbase plugin install <name> # Plugin名でインストール
# 3. プロジェクトの起動
cd projects/your-project
devbase env init # 環境変数の設定(初回のみ)
devbase build # コンテナイメージのビルド(初回のみ)
devbase up # コンテナを起動
devbase up # コンテナを起動(初回はイメージビルドを含むため時間がかかります)
devbase login # コンテナにログイン
```

Expand Down Expand Up @@ -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) を参照してください。

Expand Down
4 changes: 2 additions & 2 deletions bin/devbase
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 "$@" ;;
Expand Down
27 changes: 27 additions & 0 deletions docs/user/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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/<user>/.zshrc` |
| bash on macOS | `/Users/<user>/.bash_profile` |
| bash on Linux | `/home/<user>/.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) グループ

コンテナのライフサイクル管理を行うコマンド群です。
Expand Down
14 changes: 8 additions & 6 deletions docs/user/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. プラグインリポジトリの登録
Expand Down
1 change: 1 addition & 0 deletions etc/_devbase
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion etc/devbase-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion lib/devbase/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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']

Expand Down Expand Up @@ -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_rc import cmd_shell_rc
return cmd_shell_rc()

# --- Commands requiring DEVBASE_ROOT ---
devbase_root = _require_devbase_root()

Expand Down
15 changes: 15 additions & 0 deletions lib/devbase/commands/shell_rc.py
Original file line number Diff line number Diff line change
@@ -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
Loading