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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- name: Run shellcheck
run: |
shellcheck \
bin/xcind \
bin/xcind-application \
bin/xcind-compose \
bin/xcind-config \
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL_FILES = \
bin/xcind \
bin/xcind-application \
bin/xcind-compose \
bin/xcind-config \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ xcind-compose up -d # like `docker compose`, but resolves confi
```

That's it. `xcind-compose` is a drop-in for `docker compose` and forwards every
argument straight through. From now on it works from any subdirectory of your
argument straight through. Every command is also reachable through the `xcind`
dispatcher — `xcind compose up -d` is exactly `xcind-compose up -d`. From now on it works from any subdirectory of your
project, picks up `.override` siblings of your compose / env files, and runs
the built-in hooks (naming, host-gateway, etc.).

Expand Down
79 changes: 79 additions & 0 deletions bin/xcind
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# xcind — Dispatch to the xcind-* commands
#
# Usage:
# xcind <command> [args…]
#
# A thin dispatcher: maps the first argument to the matching xcind-<command>
# sibling binary and execs it with the remaining arguments untouched. Keeps
# no state and sources no libraries on the dispatch path so it adds no
# startup cost to the target command.

set -euo pipefail

# Resolve XCIND_ROOT by following symlinks to the real install directory
# (npm, nix profile, and manual symlinks all route through here). macOS
# lacks `readlink -f`, so the resolver is a manual loop.
# Keep in sync with the equivalent stub in the other bin/ scripts.
__xcind_src="${BASH_SOURCE[0]}"
while [ -L "$__xcind_src" ]; do
__xcind_src_dir=$(cd "$(dirname "$__xcind_src")" && pwd)
__xcind_src=$(readlink "$__xcind_src")
[[ $__xcind_src != /* ]] && __xcind_src="$__xcind_src_dir/$__xcind_src"
done
XCIND_ROOT="$(cd "$(dirname "$__xcind_src")/.." && pwd)"
unset __xcind_src __xcind_src_dir

__xcind_help() {
cat <<'HELPEOF'
Usage: xcind <command> [args…]

Dispatch to the xcind-* commands. All arguments after the command are
passed through unchanged, so `xcind compose up -d` is exactly
`xcind-compose up -d`.

Commands:
app, application Manage applications (init, status, ports, urls…)
compose Run docker compose with the resolved app config
config Inspect resolved configuration; shell completions
prompt Emit prompt data for Starship and shell prompts
proxy Manage the shared Traefik proxy
run Run bins and scripts declared in .xcind.sh
workspace Manage workspaces

Options:
--version, -V Show the xcind version
--help, -h Show this help

Run 'xcind <command> --help' for command usage.
HELPEOF
}

case "${1:-}" in
app | application)
shift
exec "$XCIND_ROOT/bin/xcind-application" "$@"
;;
compose | config | prompt | proxy | run | workspace)
__xcind_cmd="$1"
shift
exec "$XCIND_ROOT/bin/xcind-$__xcind_cmd" "$@"
;;
--version | -V | --xcind-version)
# Version needs the shared lib for the build-provenance suffix; this is
# the one non-exec path, so the sourcing cost is acceptable here.
# shellcheck disable=SC1091
source "$XCIND_ROOT/lib/xcind/xcind-bootstrap.bash"
echo "xcind $(__xcind-version-string)"
exit 0
;;
--help | -h | "")
__xcind_help
exit 0
;;
*)
echo "Error: Unknown command: $1" >&2
echo "Run 'xcind --help' for usage." >&2
exit 1
;;
esac
2 changes: 1 addition & 1 deletion contrib/test-all
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PROJECT_ROOT=$(cd "$DIR/.." && pwd)
SHFMT_IMAGE="mvdan/shfmt:v3.10.0"
SHELLCHECK_IMAGE="koalaman/shellcheck:v0.11.0"
BASH_VERSIONS=("3.2" "4.0" "4.4" "5.0" "5.1" "5" "latest")
SHELL_FILES=(bin/xcind-application bin/xcind-compose bin/xcind-config bin/xcind-prompt bin/xcind-proxy bin/xcind-run bin/xcind-workspace lib/xcind/xcind-app-lib.bash lib/xcind/xcind-app-env-lib.bash lib/xcind/xcind-assigned-lib.bash lib/xcind/xcind-bootstrap.bash lib/xcind/xcind-completion-bash.bash lib/xcind/xcind-completion-zsh.bash lib/xcind/xcind-discovery-lib.bash lib/xcind/xcind-host-gateway-lib.bash lib/xcind/xcind-hostenv-lib.bash lib/xcind/xcind-lib.bash lib/xcind/xcind-naming-lib.bash lib/xcind/xcind-proxy-lib.bash lib/xcind/xcind-registry-lib.bash lib/xcind/xcind-run-lib.bash lib/xcind/xcind-workspace-lib.bash test/test-xcind.sh test/test-xcind-proxy.sh test/test-xcind-prompt.sh test/test-xcind-completion.sh test/lib/assert.sh test/lib/setup.sh install.sh uninstall.sh)
SHELL_FILES=(bin/xcind bin/xcind-application bin/xcind-compose bin/xcind-config bin/xcind-prompt bin/xcind-proxy bin/xcind-run bin/xcind-workspace lib/xcind/xcind-app-lib.bash lib/xcind/xcind-app-env-lib.bash lib/xcind/xcind-assigned-lib.bash lib/xcind/xcind-bootstrap.bash lib/xcind/xcind-completion-bash.bash lib/xcind/xcind-completion-zsh.bash lib/xcind/xcind-discovery-lib.bash lib/xcind/xcind-host-gateway-lib.bash lib/xcind/xcind-hostenv-lib.bash lib/xcind/xcind-lib.bash lib/xcind/xcind-naming-lib.bash lib/xcind/xcind-proxy-lib.bash lib/xcind/xcind-registry-lib.bash lib/xcind/xcind-run-lib.bash lib/xcind/xcind-workspace-lib.bash test/test-xcind.sh test/test-xcind-proxy.sh test/test-xcind-prompt.sh test/test-xcind-completion.sh test/lib/assert.sh test/lib/setup.sh install.sh uninstall.sh)

# --- Color support ---

Expand Down
7 changes: 6 additions & 1 deletion docs/guides/tools-ide-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ How to wire Xcind into your shell, editor, and dev container.

## Tab completion

Xcind ships completions for `xcind-compose`, `xcind-config`, `xcind-proxy`, `xcind-run`, `xcind-application`, and `xcind-workspace`.
Xcind ships completions for `xcind` and for `xcind-compose`, `xcind-config`, `xcind-proxy`, `xcind-run`, `xcind-application`, and `xcind-workspace`.

```bash
# Bash (~/.bashrc)
Expand All @@ -16,6 +16,11 @@ Xcind ships completions for `xcind-compose`, `xcind-config`, `xcind-proxy`, `xci

`xcind-compose` delegates to Docker's own completion, so you get the full `docker compose` UX.

`xcind <TAB>` completes the command word (`app`, `compose`, `config`, …) and
then hands off to that command's own completion, so `xcind run fr<TAB>` and
`xcind compose <TAB>` behave exactly like `xcind-run fr<TAB>` and
`xcind-compose <TAB>`.

### Short names

A hand-written `x-config() { xcind-config "$@"; }` loses completion: nothing is
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

Quick reference. For exhaustive flag semantics, JSON contract, and edge cases, see [`engineering/reference/cli.md`](../../engineering/reference/cli.md).

## `xcind`

The dispatcher. `xcind <command> …` runs the matching `xcind-<command>` binary
and passes every remaining argument through unchanged, so `xcind compose up -d`
is exactly `xcind-compose up -d`. `app` is an alias for `application`.

```bash
xcind compose up -d # = xcind-compose up -d
xcind run fresh # = xcind-run fresh
xcind app status # = xcind-application status
xcind --help # list the commands
```

Tab completion covers the command word and then continues with the selected
command's own completion.

## `xcind-compose`

The main wrapper around `docker compose`. Resolves files, applies hooks, forwards everything else.
Expand Down
6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
description = "Docker Compose environment manager (unwrapped — bring your own jq/yq/docker)";
license = licenses.mit;
platforms = platforms.unix;
mainProgram = "xcind-compose";
mainProgram = "xcind";
};
});

Expand All @@ -120,6 +120,8 @@
# the assigned-ports state as a JSON array.
proxyPath = pkgs.lib.makeBinPath (core ++ json ++ docker);
in writeBuildInfo + ''
wrapProgram "$out/bin/xcind" \
--prefix PATH : ${fullPath}
wrapProgram "$out/bin/xcind-application" \
--prefix PATH : ${fullPath}
wrapProgram "$out/bin/xcind-compose" \
Expand All @@ -139,7 +141,7 @@
description = "Docker Compose environment manager";
license = licenses.mit;
platforms = platforms.unix;
mainProgram = "xcind-compose";
mainProgram = "xcind";
};
});
in
Expand Down
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ echo "Installing xcind to $PREFIX ..."
install -d "$PREFIX/bin"
install -d "$PREFIX/lib/xcind"

install -m 755 "$XCIND_ROOT/bin/xcind" "$PREFIX/bin/xcind"
install -m 755 "$XCIND_ROOT/bin/xcind-application" "$PREFIX/bin/xcind-application"
install -m 755 "$XCIND_ROOT/bin/xcind-compose" "$PREFIX/bin/xcind-compose"
install -m 755 "$XCIND_ROOT/bin/xcind-config" "$PREFIX/bin/xcind-config"
Expand Down
41 changes: 41 additions & 0 deletions lib/xcind/xcind-completion-bash.bash
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,51 @@ _xcind_run_completions() {
fi
}

# -----------------------------------------------------------------------------
# xcind: dispatcher — complete the command, then delegate
# -----------------------------------------------------------------------------

# The per-command functions above key off word positions and never read the
# command name at word 0 (that is what lets the x-* wrappers reuse them).
# So after the command word is chosen, re-seat COMP_WORDS/COMP_CWORD as if
# the user had typed `xcind-<command> …` and delegate to the matching
# function. _xcind_compose_completions' ${COMP_WORDS[@]:1} slice then
# forwards exactly the user's compose arguments to `docker __complete`.
_xcind_completions() {
local cur="${COMP_WORDS[COMP_CWORD]}"

if [[ $COMP_CWORD -le 1 ]]; then
local commands="app application compose config prompt proxy run workspace --help -h --version -V"
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
return
fi

local fn=""
case "${COMP_WORDS[1]}" in
app | application) fn=_xcind_application_completions ;;
compose) fn=_xcind_compose_completions ;;
config) fn=_xcind_config_completions ;;
proxy) fn=_xcind_proxy_completions ;;
run) fn=_xcind_run_completions ;;
workspace) fn=_xcind_workspace_completions ;;
# prompt has no completion of its own; unknown words offer nothing
*) return ;;
esac

COMP_WORDS=("xcind-${COMP_WORDS[1]}" "${COMP_WORDS[@]:2}")
((COMP_CWORD--))
"$fn"
}

# -----------------------------------------------------------------------------
# Register completions
# -----------------------------------------------------------------------------

# The dispatcher registration is intentionally absent from
# __XCIND_SHELL_ALIAS_MAP below: the map drives x-* wrappers over the
# xcind-* binaries, and the drift guard in test-xcind-completion.sh only
# matches `xcind-` names.
complete -F _xcind_completions xcind
complete -F _xcind_application_completions xcind-application
complete -F _xcind_application_completions xcind-app
complete -F _xcind_compose_completions xcind-compose
Expand Down
53 changes: 53 additions & 0 deletions lib/xcind/xcind-completion-zsh.bash
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,63 @@ _xcind-run() {
fi
}

# -----------------------------------------------------------------------------
# xcind: dispatcher — complete the command, then delegate
# -----------------------------------------------------------------------------

# The per-command functions above key off word positions and never read the
# command name at words[1] (that is what lets the x-* wrappers reuse them).
# So after the command word is chosen, re-seat words/CURRENT as if the user
# had typed `xcind-<command> …` and delegate to the matching function.
# _xcind-compose's ${words[@]:1} slice then forwards exactly the user's
# compose arguments to `docker __complete`.
_xcind() {
if ((CURRENT == 2)); then
local -a commands=(
'app:Manage applications (alias for application)'
'application:Manage applications (init, status, ports, urls…)'
'compose:Run docker compose with the resolved app config'
'config:Inspect resolved configuration; shell completions'
'prompt:Emit prompt data for Starship and shell prompts'
'proxy:Manage the shared Traefik proxy'
'run:Run bins and scripts declared in .xcind.sh'
'workspace:Manage workspaces'
'--help:Show help'
'-h:Show help'
'--version:Show version'
'-V:Show version'
)
_describe 'xcind command' commands
return
fi

local cmd="${words[2]}" fn=""
case "$cmd" in
app | application) fn=_xcind-application ;;
compose) fn=_xcind-compose ;;
config) fn=_xcind-config ;;
proxy) fn=_xcind-proxy ;;
run) fn=_xcind-run ;;
workspace) fn=_xcind-workspace ;;
# prompt has no completion of its own; unknown words offer nothing
*) return 1 ;;
esac

words=("xcind-$cmd" "${words[@]:2}")
((CURRENT--))
local service="xcind-$cmd"
"$fn"
}

# -----------------------------------------------------------------------------
# Register completions
# -----------------------------------------------------------------------------

# The dispatcher registration is intentionally absent from
# __XCIND_SHELL_ALIAS_MAP below: the map drives x-* wrappers over the
# xcind-* binaries, and the drift guard in test-xcind-completion.sh only
# matches `xcind-` names.
compdef _xcind xcind
compdef _xcind-application xcind-application
compdef _xcind-application xcind-app
compdef _xcind-compose xcind-compose
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.7.3",
"description": "Slim shell wrapper around docker compose with per-application config",
"bin": {
"xcind": "bin/xcind",
"xcind-app": "bin/xcind-application",
"xcind-application": "bin/xcind-application",
"xcind-compose": "bin/xcind-compose",
Expand Down
Loading
Loading