Skip to content

Instantly share code, notes, and snippets.

@goropikari
Last active August 9, 2025 06:31
Show Gist options
  • Select an option

  • Save goropikari/ae673cb335865cfdc3d389d61ebc7484 to your computer and use it in GitHub Desktop.

Select an option

Save goropikari/ae673cb335865cfdc3d389d61ebc7484 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
# Get the current absolute path and mangle it
CWD=$(pwd)
# remove leading / and replace / with _
MANGLED_PATH=$(echo "$CWD" | sed 's/^\///' | sed 's/\//_/g')
DEVENV_DIR="$HOME/.config/devc/$MANGLED_PATH"
OVERRIDE_JSONC="$DEVENV_DIR/override.jsonc"
UNITE_JSON=".devcontainer/devcontainer_unite.json"
# Ensure the config directory exists
mkdir -p "$DEVENV_DIR"
# Main command logic
COMMAND=${1:-}
case "$COMMAND" in
"edit")
# Open the override file in the default editor
if [ ! -f "$OVERRIDE_JSONC" ]; then
echo "{}" > "$OVERRIDE_JSONC"
fi
${EDITOR:-vim} "$OVERRIDE_JSONC"
;;
"up")
shift || true # remove "up" from arguments list
# Default path to the project's devcontainer.json
DEVCONTAINER_JSON_PATH=".devcontainer/devcontainer.json"
# Check if the project's devcontainer.json exists
if [ ! -f "$DEVCONTAINER_JSON_PATH" ]; then
echo "Error: devcontainer file not found at '$DEVCONTAINER_JSON_PATH'"
exit 1
fi
# Check if unitejson is installed
if ! command -v unitejson &> /dev/null; then
# echo "Error: unitejson is not installed. Please install it to use the 'up' command."
# exit 1
go install github.com/goropikari/unitejson@latest
fi
# Prepare arguments for unitejson
UNITE_ARGS=("$DEVCONTAINER_JSON_PATH")
if [ -f "$OVERRIDE_JSONC" ]; then
UNITE_ARGS+=("$OVERRIDE_JSONC")
fi
# Create the unite.json file
echo "Creating $UNITE_JSON..."
unitejson "${UNITE_ARGS[@]}" > "$UNITE_JSON"
# Run devpod
echo "Running devpod..."
export TERM=xterm-256color
devpod up . --devcontainer-path "$UNITE_JSON" --ide none
;;
*)
echo "Usage: devc [edit|up]"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment