From 40f98088299b756c4d33e8cb07ce1162001bcc1a Mon Sep 17 00:00:00 2001 From: Hanashiko Date: Tue, 6 May 2025 18:21:25 +0300 Subject: [PATCH 1/4] feat(magento2): initial creating magento2 plugin --- plugins/magento2/magento2.plugin.zsh | 165 +++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 plugins/magento2/magento2.plugin.zsh diff --git a/plugins/magento2/magento2.plugin.zsh b/plugins/magento2/magento2.plugin.zsh new file mode 100644 index 000000000..76b0ac530 --- /dev/null +++ b/plugins/magento2/magento2.plugin.zsh @@ -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 From cc979a6e747e3e98bfffe3fa81fee913ab1c7e73 Mon Sep 17 00:00:00 2001 From: Hanashiko Date: Tue, 6 May 2025 18:28:19 +0300 Subject: [PATCH 2/4] docs(magento2): wrote the documentation for the plugin --- plugins/magento2/README.md | 179 +++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 plugins/magento2/README.md diff --git a/plugins/magento2/README.md b/plugins/magento2/README.md new file mode 100644 index 000000000..920569b95 --- /dev/null +++ b/plugins/magento2/README.md @@ -0,0 +1,179 @@ +# Magento 2 Oh My Zsh 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 + +## License + +This plugin is released under the MIT License. + +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. From 573ce90b4e481e58687b3a30003cb21c60d88e17 Mon Sep 17 00:00:00 2001 From: Hanashiko Date: Tue, 6 May 2025 18:30:14 +0300 Subject: [PATCH 3/4] docs(magento2): removed possibly unnecessary items in the documentation --- plugins/magento2/README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/plugins/magento2/README.md b/plugins/magento2/README.md index 920569b95..b5a007d50 100644 --- a/plugins/magento2/README.md +++ b/plugins/magento2/README.md @@ -169,11 +169,3 @@ m2mainton - 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 - -## License - -This plugin is released under the MIT License. - -## Contributing - -Contributions are welcome! Please feel free to submit a Pull Request. From b1c15ccb24167bb0c55950d5206afac48cc8a2ff Mon Sep 17 00:00:00 2001 From: Hanashiko Date: Tue, 6 May 2025 19:34:23 +0300 Subject: [PATCH 4/4] docs(magento2): wrote thorough documentation for the nmap plugin --- plugins/magento2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/magento2/README.md b/plugins/magento2/README.md index b5a007d50..fa4b4a33a 100644 --- a/plugins/magento2/README.md +++ b/plugins/magento2/README.md @@ -1,4 +1,4 @@ -# Magento 2 Oh My Zsh Plugin +# 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.