mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-05 01:46:46 +01:00
Merge b1c15ccb24 into e9fc134236
This commit is contained in:
commit
ee34ce8bb4
2 changed files with 336 additions and 0 deletions
171
plugins/magento2/README.md
Normal file
171
plugins/magento2/README.md
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
# Magento 2 plugin
|
||||
|
||||
This plugin provides a powerful set of shortcuts, aliases, and utilities to simplify and enhance your Magento 2 development workflow in the command line.
|
||||
|
||||
## Installation
|
||||
|
||||
To use it, add `magento2` to the plugins array in your zshrc file:
|
||||
|
||||
```
|
||||
plugins=(... magento2)
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Automatic Magento root directory detection
|
||||
- Shorthand commands for common Magento 2 CLI operations
|
||||
- Admin user management
|
||||
- Database information retrieval
|
||||
- System status overview
|
||||
- Quick cache and temporary file cleanup
|
||||
- Deployment and module management helpers
|
||||
|
||||
## Usage Guide
|
||||
|
||||
### Basic Commands
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2` | Base Magento CLI command with unlimited memory | `m2 [command]` |
|
||||
| `mg-cd` | Navigate to Magento root directory | `mg-cd` |
|
||||
| `mg-set-root` | Set current directory as Magento root | `mg-set-root` |
|
||||
| `mg-status` | Display comprehensive system status | `mg-status` |
|
||||
|
||||
### Cache Management
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2cc` | Clean cache | `m2cc` |
|
||||
| `m2cf` | Flush cache | `m2cf` |
|
||||
| `mg-clean` | Remove temporary files and flush cache | `mg-clean` |
|
||||
|
||||
### Setup and Deployment
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2setup` | Run setup:upgrade | `m2setup` |
|
||||
| `m2dicom` | Compile Dependency Injection | `m2dicom` |
|
||||
| `m2deploy` | Deploy static content | `m2deploy` |
|
||||
| `m2st` | Full setup (upgrade, compile, deploy) | `m2st` |
|
||||
| `mg-update` | Complete system update | `mg-update` |
|
||||
| `mg-deploy-langs` | Deploy for specific languages | `mg-deploy-langs "en_US fr_FR"` |
|
||||
|
||||
### Mode Management
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2mode` | Show current mode | `m2mode` |
|
||||
| `m2dev` | Set developer mode | `m2dev` |
|
||||
| `m2prod` | Set production mode | `m2prod` |
|
||||
|
||||
### Maintenance
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2maint` | Check maintenance status | `m2maint` |
|
||||
| `m2mainton` | Enable maintenance mode | `m2mainton` |
|
||||
| `m2maintoff` | Disable maintenance mode | `m2maintoff` |
|
||||
|
||||
### Module Management
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2module` or `m2mod` | List all modules and status | `m2module` |
|
||||
| `m2enable` | Enable a module | `m2enable Vendor_Module` |
|
||||
| `m2disable` | Disable a module | `m2disable Vendor_Module` |
|
||||
| `mg-module` | Module management function | `mg-module enable Vendor_Module` |
|
||||
|
||||
### Indexing
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2index` | Show indexer status | `m2index` |
|
||||
| `m2indexr` | Reindex all indices | `m2indexr` |
|
||||
|
||||
### Admin User Management
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `mg-admin-create` | Create admin user | `mg-admin-create [username] [email] [firstname] [lastname] [password]` |
|
||||
| `mg-admin-password` | Change admin password | `mg-admin-password [username] [new_password]` |
|
||||
|
||||
### Database Information
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `mg-db-info` | Show database connection info | `mg-db-info` |
|
||||
|
||||
### Logging
|
||||
|
||||
| Alias/Command | Description | Usage |
|
||||
|---------------|-------------|-------|
|
||||
| `m2log` | Tail system log | `m2log` |
|
||||
| `m2elog` | Tail exception log | `m2elog` |
|
||||
| `m2debug` | Tail debug log | `m2debug` |
|
||||
|
||||
## Example Workflows
|
||||
|
||||
### Initial Setup
|
||||
|
||||
```bash
|
||||
# Navigate to your Magento project
|
||||
cd ~/projects/my-magento-store
|
||||
|
||||
# Set as Magento root if not automatically detected
|
||||
mg-set-root
|
||||
|
||||
# Check system status
|
||||
mg-status
|
||||
|
||||
# Create admin user
|
||||
mg-admin-create "admin" "admin@gmail.com" "Hanashiko" "Margin" "securepassword123"
|
||||
```
|
||||
|
||||
### Development Workflow
|
||||
|
||||
```bash
|
||||
# Switch to developer mode
|
||||
m2dev
|
||||
|
||||
# Enable a custom module
|
||||
m2enable MyCompany_CustomModule
|
||||
|
||||
# Update system after changes
|
||||
mg-update
|
||||
|
||||
# Or individual steps:
|
||||
m2setup # Update database schema
|
||||
m2dicom # Compile code
|
||||
m2deploy # Deploy static content
|
||||
m2indexr # Reindex
|
||||
```
|
||||
|
||||
### Cleanup Operations
|
||||
|
||||
```bash
|
||||
# Quick cleanup of temporary files
|
||||
mg-clean
|
||||
|
||||
# Or individual operations
|
||||
m2cf # Flush cache
|
||||
```
|
||||
|
||||
### Deployment Preparation
|
||||
|
||||
```bash
|
||||
# Switch to production mode
|
||||
m2prod
|
||||
|
||||
# Deploy for multiple languages
|
||||
mg-deploy-langs "en_US de_DE fr_FR"
|
||||
|
||||
# Enable maintenance mode before deployment
|
||||
m2mainton
|
||||
```
|
||||
|
||||
## Tips and Tricks
|
||||
|
||||
- Use `mg-cd` to quickly navigate to the Magento root from any subdirectory
|
||||
- Run `mg-status` to get a comprehensive overview of your system
|
||||
- Use tab completion with `m2` to explore available Magento CLI commands
|
||||
- The `mg-update` command combines multiple setup steps into a single command
|
||||
165
plugins/magento2/magento2.plugin.zsh
Normal file
165
plugins/magento2/magento2.plugin.zsh
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
# Oh My Zsh plugin for Magento 2
|
||||
|
||||
# Basic settings and variables
|
||||
export MAGENTO_ROOT=${MAGENTO_ROOT:-$(pwd)}
|
||||
|
||||
# Function to determine the Magento root directory
|
||||
function _get_magento_root() {
|
||||
local dir=$PWD
|
||||
while [[ $dir != "/" ]]; do
|
||||
if [[ -f "$dir/app/etc/env.php" || (-f "$dir/composer.json" && -d "$dir/vendor/magento") ]]; then
|
||||
echo $dir
|
||||
return 0
|
||||
fi
|
||||
dir=${dir:h}
|
||||
done
|
||||
echo $MAGENTO_ROOT
|
||||
}
|
||||
|
||||
# Set Magento root
|
||||
function mg-set-root() {
|
||||
export MAGENTO_ROOT=$(pwd)
|
||||
echo "Magento root set to: $MAGENTO_ROOT"
|
||||
}
|
||||
|
||||
# Navigate to Magento root directory
|
||||
function mg-cd() {
|
||||
local root=$(_get_magento_root)
|
||||
cd $root
|
||||
echo "Changed to Magento directory: $root"
|
||||
}
|
||||
|
||||
# Aliases for console commands
|
||||
alias m2="php -d memory_limit=-1 bin/magento"
|
||||
alias m2cc="m2 cache:clean"
|
||||
alias m2cf="m2 cache:flush"
|
||||
alias m2st="m2 setup:upgrade && m2 setup:di:compile && m2 setup:static-content:deploy -f"
|
||||
alias m2setup="m2 setup:upgrade"
|
||||
alias m2dicom="m2 setup:di:compile"
|
||||
alias m2deploy="m2 setup:static-content:deploy -f"
|
||||
alias m2mode="m2 deploy:mode:show"
|
||||
alias m2dev="m2 deploy:mode:set developer"
|
||||
alias m2prod="m2 deploy:mode:set production"
|
||||
alias m2maint="m2 maintenance:status"
|
||||
alias m2mainton="m2 maintenance:enable"
|
||||
alias m2maintoff="m2 maintenance:disable"
|
||||
alias m2module="m2 module:status"
|
||||
alias m2mod="m2 module:status"
|
||||
alias m2enable="m2 module:enable"
|
||||
alias m2disable="m2 module:disable"
|
||||
alias m2index="m2 indexer:status"
|
||||
alias m2indexr="m2 indexer:reindex"
|
||||
alias m2log="tail -f var/log/system.log"
|
||||
alias m2elog="tail -f var/log/exception.log"
|
||||
alias m2debug="tail -f var/log/debug.log"
|
||||
|
||||
# Function for enabling/disabling modules
|
||||
function mg-module() {
|
||||
if [[ $1 == "enable" && -n $2 ]]; then
|
||||
m2 module:enable $2
|
||||
elif [[ $1 == "disable" && -n $2 ]]; then
|
||||
m2 module:disable $2
|
||||
else
|
||||
m2 module:status
|
||||
fi
|
||||
}
|
||||
|
||||
# Create administrator
|
||||
function mg-admin-create() {
|
||||
local username=${1:-"admin"}
|
||||
local email=${2:-"admin@example.com"}
|
||||
local firstname=${3:-"Admin"}
|
||||
local lastname=${4:-"User"}
|
||||
local password=${5:-"admin123"}
|
||||
|
||||
m2 admin:user:create --admin-user=$username --admin-password=$password --admin-email=$email --admin-firstname=$firstname --admin-lastname=$lastname
|
||||
echo "Administrator created: $username ($email)"
|
||||
}
|
||||
|
||||
# Change administrator password
|
||||
function mg-admin-password() {
|
||||
local username=${1:-"admin"}
|
||||
local password=${2:-"admin123"}
|
||||
|
||||
m2 admin:user:unlock $username
|
||||
m2 admin:user:create --admin-user=$username --admin-password=$password --admin-email="" --admin-firstname="" --admin-lastname="" --magento-init-params="--no-interaction"
|
||||
echo "Password for $username changed to $password"
|
||||
}
|
||||
|
||||
# Work with database
|
||||
function mg-db-info() {
|
||||
local root=$(_get_magento_root)
|
||||
if [[ -f "$root/app/etc/env.php" ]]; then
|
||||
php -r '
|
||||
$env = include "'$root'/app/etc/env.php";
|
||||
if (isset($env["db"]["connection"]["default"])) {
|
||||
$db = $env["db"]["connection"]["default"];
|
||||
echo "DB Host: " . $db["host"] . "\n";
|
||||
echo "DB Name: " . $db["dbname"] . "\n";
|
||||
echo "DB User: " . $db["username"] . "\n";
|
||||
} else {
|
||||
echo "Database configuration not found\n";
|
||||
}
|
||||
'
|
||||
else
|
||||
echo "Magento configuration file not found"
|
||||
fi
|
||||
}
|
||||
|
||||
# Deploy multilanguage static files
|
||||
function mg-deploy-langs() {
|
||||
local langs=${1:-"en_US"}
|
||||
m2 setup:static-content:deploy -f $langs
|
||||
}
|
||||
|
||||
# Quick system update (all in one command)
|
||||
function mg-update() {
|
||||
local root=$(_get_magento_root)
|
||||
cd $root
|
||||
|
||||
echo "=== Starting Magento update ==="
|
||||
echo "1. Clearing cache..."
|
||||
m2 cache:flush
|
||||
echo "2. Updating database..."
|
||||
m2 setup:upgrade
|
||||
echo "3. Compiling DI..."
|
||||
m2 setup:di:compile
|
||||
echo "4. Deploying static files..."
|
||||
m2 setup:static-content:deploy -f
|
||||
echo "5. Reindexing..."
|
||||
m2 indexer:reindex
|
||||
echo "=== Update completed ==="
|
||||
}
|
||||
|
||||
# Function to check system status
|
||||
function mg-status() {
|
||||
local root=$(_get_magento_root)
|
||||
cd $root
|
||||
|
||||
echo "=== Magento 2 Status ==="
|
||||
echo "Working mode:"
|
||||
m2 deploy:mode:show
|
||||
echo "\nMaintenance status:"
|
||||
m2 maintenance:status
|
||||
echo "\nIndex status:"
|
||||
m2 indexer:status
|
||||
echo "\nCache status:"
|
||||
m2 cache:status
|
||||
echo "===================="
|
||||
}
|
||||
|
||||
# Function for quick cleanup of temporary files
|
||||
function mg-clean() {
|
||||
local root=$(_get_magento_root)
|
||||
cd $root
|
||||
|
||||
echo "Cleaning temporary files and cache..."
|
||||
rm -rf var/cache/* var/page_cache/* var/view_preprocessed/* pub/static/frontend/* pub/static/adminhtml/* var/di/* generated/code/*
|
||||
m2 cache:flush
|
||||
echo "Cleanup completed."
|
||||
}
|
||||
|
||||
# Command completion for Magento CLI commands
|
||||
compdef '_arguments "1: :((cache\:"Cache operations" setup\:"Setup operations" module\:"Module operations" deploy\:"Deploy operations" indexer\:"Indexer operations" admin\:"Admin operations" dev\:"Dev operations" maintenance\:"Maintenance operations" config\:"Config operations"))"' m2
|
||||
Loading…
Add table
Add a link
Reference in a new issue