Pine Works logo
Sponsored by
Pine Works

Need more than templates? Pine Works can bring your project across the finish line with custom development and integrations for Craft CMS.

Custom DDEV Commands

Learn how to create a custom DDEV command that opens your Craft CMS Control Panel at the correct URL, even when you've customized the cpTrigger.

Craft 5

Free

Localhosting DDEV

Here are a few help­ful details on the code that I didn’t cov­er in the video. Con­sid­er this some extra credit!

Com­ments

The com­ments at the top of the file have a pur­pose: to inform the devel­op­er and pro­vide con­tent to the help output.

#!/usr/bin/env bash                           # Portable shebang - finds bash anywhere
## Description: Launch Craft CMS Control Panel (reads CRAFT_CP_TRIGGER from .env)
## Usage: launch-cp                             
## Example: "ddev launch-cp"                    
  • She­bang line: #!/usr/bin/env bash is more portable than #!/bin/bash
  • Descrip­tion: Shows in ddev help output
  • Usage/​Example: Pro­vides clear guid­ance for team members

Envi­ron­ment Vari­able Parsing

Find lines start­ing with CRAFT_CP_TRIGGER= in the .env file:

grep "^CRAFT_CP_TRIGGER=" .env

Get only what comes after the = sign:

cut -d'=' -f2

And then remove any quotes, just so you have the val­ue of CRAFT_CP_TRIGGER:

tr -d '"' | tr -d "'"

DDEV Envi­ron­ment Variables

DDEV_HOSTNAME is auto­mat­i­cal­ly pro­vid­ed by DDEV and there are oth­er DDEV-pro­vid­ed envi­ron­ment vari­ables avail­able to use in a cus­tom command.