Skip to content

Instantly share code, notes, and snippets.

@mralaminahamed
Created March 1, 2026 06:20
Show Gist options
  • Select an option

  • Save mralaminahamed/b429b9574a1bde85b363c9b58c7f1d02 to your computer and use it in GitHub Desktop.

Select an option

Save mralaminahamed/b429b9574a1bde85b363c9b58c7f1d02 to your computer and use it in GitHub Desktop.
Create new plugin from Codexprt boilerplate
cpb() {
local type name slug package prefix constant description
print -n 'Type (1: Classic / 2: Basic / 3: Modern): ' && read -r type
print -n 'Name: ' && read -r name
print -n 'Slug: ' && read -r slug
print -n 'Package: ' && read -r package
print -n 'Prefix: ' && read -r prefix
print -n 'Constant: ' && read -r constant
print -n 'Description: ' && read -r description
# Clone the appropriate boilerplate branch
case "$type" in
1) git clone https://github.com/codexpertio/cx-plugin.git "$slug" ;;
2) git clone -b client https://github.com/codexpertio/cx-plugin.git "$slug" ;;
3) git clone -b modern https://github.com/codexpertio/cx-plugin.git "$slug" ;;
*) print "Invalid type. Aborting." && return 1 ;;
esac
cd "$slug" || { print "Failed to enter directory: $slug"; return 1; }
# Rename main plugin file
mv "cx-plugin.php" "$slug.php"
# Helper: perform in-place replacement across all readable/writable files
_replace() {
find ./ -type f -readable -writable -exec sed -i "s/$1/$2/g" {} \;
}
[[ -n "$name" ]] && _replace "CX Plugin" "$name"
[[ -n "$slug" ]] && _replace "cx-plugin" "$slug"
[[ -n "$package" ]] && _replace "CX_Plugin" "$package"
[[ -n "$prefix" ]] && _replace "cxp" "$prefix"
[[ -n "$prefix" ]] && _replace "cx_plugin" "$prefix"
[[ -n "$constant" ]] && _replace "CXP" "$constant"
[[ -n "$description" ]] && _replace "Just another plugin by Codexpert" "$description"
composer install # Install Composer dependencies
rm -rf .git # Remove cloned repo's Git history
gi # Re-initialise Git
ga # Stage all files
gc -m "init" # Initial commit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment