diff --git a/README.md b/README.md index ac74962..a496db0 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ Reusable Dev Containers for any project — without modifying the repository. - [Background](#background) - [Install](#install) - [Usage](#usage) -- [API](#api) - [Configuration](#configuration) - [Template System](#template-system) - [File Injection](#file-injection) +- [API](#api) - [Contributing](#contributing) - [License](#license) @@ -56,7 +56,7 @@ Typical Dev Container workflows involve: ## Install -### Prerequisites +### Dependencies - VS Code with the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension - Docker @@ -81,15 +81,15 @@ devcode open ~/projects/my-app dev-code ### Typical Workflow ```bash -devcode new python-dev -devcode edit python-dev +devcode template new python-dev +devcode template edit python-dev devcode open ~/projects/my-app python-dev ``` ### Project Switching ```bash -devcode ps -a -i +devcode list -a -i ``` Lists containers and allows reopening projects interactively. @@ -97,7 +97,6 @@ Lists containers and allows reopening projects interactively. ### Advanced Options - Multiple template directories -- Template inheritance - Verbose debugging (`-v`) - Dry runs (`--dry-run`) - Custom container paths @@ -111,257 +110,332 @@ Lists containers and allows reopening projects interactively. --- -## API +## Configuration -Full reference for all `devcode` commands and flags. +devcode reads `settings.json` from: -### Global Flags +``` +~/.config/dev-code/settings.json +``` + +Override the config directory: ```bash --v, --verbose Enable debug output +DEVCODE_CONF_DIR=/custom/path devcode open ~/projects/my-app ``` +The file is created automatically with defaults on first run. + +### settings.json + +```json +{ + "template_sources": ["~/.local/share/dev-code/templates"], + "default_template": "dev-code", + "template_write_dir": null +} +``` + +| Key | Description | +| --- | --- | +| `template_sources` | Ordered list of template directories searched when resolving templates. | +| `default_template` | Template used when `devcode open` is called without a template argument and no container history is found. Error if unset. | +| `template_write_dir` | Directory where `devcode template new` writes new templates. `null` (default) uses the XDG data home: `~/.local/share/dev-code/templates`. Overridden per-invocation by `--path`. | + --- -### devcode open +## Template System -```bash -devcode open [template] [options] +### Default Location + +``` +~/.local/share/dev-code/templates/ ``` -Open a project in VS Code using a devcontainer template. +Configure additional paths via `template_sources` in `settings.json` (see [Configuration](#configuration)). -#### Arguments +--- -* `` — Project directory (must exist) +## File Injection -* `[template]` *(optional)* +Inject files from the host into the container at startup. - * Template name, or - * Path to a `devcontainer.json`, or - * Path to a directory containing it +### Example - Paths must start with `./`, `../`, `/`, or `~/`. +```json +{ + "customizations": { + "dev-code": { + "cp": [ + { + "source": "${localEnv:HOME}/.config/myapp", + "target": "/home/vscode/.config/myapp" + } + ] + } + } +} +``` - If both a template name and a local directory match, the template takes precedence and a warning is shown. +### Fields - **If omitted**, devcode auto-detects the template in this order: - 1. Most recently running container for this project path (uses its stored config) - 2. Most recently stopped container for this project path - 3. `default_template` from `settings.json` (error if not set) +| Field | Required | Description | +| ------------- | -------- | -------------------------------------- | +| `source` | Yes | Host path | +| `target` | Yes | Container path | +| `override` | No | Skip if target exists (default: false) | +| `owner` | No | Requires `group` | +| `group` | No | Requires `owner` | +| `permissions` | No | chmod applied recursively | -#### Options +### Source Behavior -| Option | Default | Description | -| --------------------------- | ----------------------- | ---------------------------------------------------------- | -| `--dry-run` | — | Print resolved configuration and actions without executing | -| `--container-folder ` | resolved from devcontainer config | Container mount path | -| `--timeout ` | `300` | Time to wait for container startup | +* Supports `${localEnv:VAR}` +* Supports relative paths from `.devcontainer/` +* Missing environment variables cause the entry to be skipped ---- +### Copy Directory Contents -### devcode new +Use `/.` suffix: -```bash -devcode new [base] +```json +{ + "source": "${localEnv:HOME}/.config/myapp/.", + "target": "/home/vscode/.config/myapp/" +} ``` -Create a new template. +Copies directory contents instead of the directory itself. -| Argument | Default | Description | -| -------- | ---------- | --------------------- | -| `[base]` | `dev-code` | Template to copy from | +### Behavior Rules + +* `target/` copies into the directory +* Without trailing `/` copies as a file or directory +* `override=false` skips existing files +* Ownership and permissions are applied after copying + +--- + +## API -Options: +Full reference for all `devcode` commands and flags. + +### Global Flags ```bash ---edit +-v, --verbose Enable debug output +--version Show version and exit ``` -Open the template in VS Code after creation. - --- -### devcode edit +### devcode open ```bash -devcode edit [template] +devcode open [template] [options] ``` -* With a name: opens that template -* Without arguments: opens the templates directory +Open a project in VS Code using a devcontainer template. + +#### Arguments + +* `` — Project directory (must exist) +* `[template]` *(optional)* — Template name, path to a `devcontainer.json`, or path to a directory containing it. Paths must start with `./`, `../`, `/`, or `~/`. If omitted, devcode resolves in this order: + 1. Most recently running container for this project path + 2. Most recently stopped container for this project path + 3. `default_template` from `settings.json` (error if not set) + +#### Options + +| Option | Default | Description | +| --- | --- | --- | +| `--dry-run` | — | Print resolved configuration and actions without executing | +| `--container-folder ` | resolved from devcontainer config | Container mount path | +| `--timeout ` | `300` | Time to wait for container startup | --- ### devcode list ```bash -devcode list [--long] +devcode list [-a] [-i] ``` -| Option | Description | -| -------- | --------------------------------------- | -| `--long` | Show full paths and grouped directories | +List dev containers. + +| Flag | Description | +| --- | --- | +| `-a, --all` | Include stopped containers | +| `-i, --interactive` | Prompt to reopen a listed container | + +Interactive mode prompts `Open [1-N]:` — selecting a number reopens the project in VS Code. --- -### devcode ps +### devcode prune ```bash -devcode ps [-a] [-i] +devcode prune [path] [options] ``` -| Flag | Description | -| ---- | -------------------------- | -| `-a` | Include stopped containers | -| `-i` | Interactive reopen mode | +Remove stopped dev containers. Either `[path]` or `--all-projects` is required. -Interactive mode prompts: +#### Arguments -``` -Open [1-N]: -``` +* `[path]` *(optional)* — Limit pruning to containers for this project directory. + +#### Options -Selecting a number reopens the project in VS Code. +| Option | Description | +| --- | --- | +| `--all-projects` | Prune stopped containers across all projects | +| `--include-recent` | Also prune the most recently used container (skipped by default) | --- -### devcode completion +### devcode template ```bash -devcode completion bash -devcode completion zsh +devcode template ``` -Enable in shell: +Manage dev container templates. + +--- + +#### devcode template new ```bash -eval "$(devcode completion bash)" +devcode template new [base] [options] ``` ---- +Create a new template by copying a base template. -## Configuration +| Argument | Default | Description | +| --- | --- | --- | +| `[base]` | `dev-code` | Template to copy from | -devcode reads `settings.json` from: +| Option | Description | +| --- | --- | +| `--edit` | Launch the new template as a Dev Container in VS Code after creation | +| `--path ` | Write the new template into `` instead of the configured write target | -``` -~/.config/dev-code/settings.json -``` +--- -Override the config directory: +#### devcode template edit ```bash -DEVCODE_CONF_DIR=/custom/path devcode open ~/projects/my-app +devcode template edit