Skip to content

Instantly share code, notes, and snippets.

@rehanmobin
Created January 23, 2019 16:32
Show Gist options
  • Save rehanmobin/b6bb04e3545689f0fba5dbad51a67d8f to your computer and use it in GitHub Desktop.
Save rehanmobin/b6bb04e3545689f0fba5dbad51a67d8f to your computer and use it in GitHub Desktop.
Run Magento2 most common commands with short alisas
#!/usr/bin/env bash
#path to php binary
PHP=`which php`
cacheHelp()
{
echo "
\"-cache | -c\" Cache commands
Options:
\"-sts\" To view the cache types and their status, enter \"-c -sts\"
\"-cln\" To clean out magento cache types, enter \"-c -cln\"
\"-fls\" To flush every thing from magento cache enter \"-c -flush\"
"
}
reindexHelp()
{
echo "
\"-r_ind\" Re-index all"
}
developerModeHelp()
{
echo "
\"-dev_mode\" Developer mode commands.
1. Set the current Magento mode developer
2. Setup upgrade
3. Setup DI compile
4. static-content force deploy
"
}
productionModeHelp()
{
echo "
\"-prd_mode\" Production mode commands.
1. Set the current Magento mode production
2. Setup upgrade
3. Setup DI compile
4. static-content force deploy
"
}
usage()
{
echo "
This bash scripts let's a developer run most common magento commands without writing complete command syntax.
Usage:
./cmd [command-name] [additional-arguments]
OR
bash mage [command-name] [additional-arguments]
\"-h | --help\" for usage help.
Commands:"
cacheHelp
reindexHelp
developerModeHelp
productionModeHelp
echo "
\"-upg\" Setup upgrade command
\"-dic\" Setup di compile command
\"-stcd\" Setup static content deploy command with force
"
}
cacheCmd()
{
if [ $1 = "-sts" ]; then
$PHP bin/magento cache:status
elif [ $1 = "-cln" ]; then
$PHP bin/magento cache:clean
elif [ $1 = "-fls" ]; then
$PHP bin/magento cache:flush
else
cacheHelp
fi;
}
reindexAllCmd()
{
echo "Running Reindex all ..."
$PHP bin/magento indexer:reindex
}
upgradeCmd()
{
echo "Running setup upgrade command ..."
$PHP bin/magento setup:upgrade
}
diCompileCmd()
{
echo "Running setup di compile command ..."
$PHP bin/magento setup:di:compile
}
contentDeployCmd()
{
echo "Running static content deploy command ..."
$PHP bin/magento setup:static-content:deploy -f
}
developerModeCmd()
{
echo "Changing current Magento env to developer ..."
$PHP bin/magento deploy:mode:set developer -s
upgradeCmd
diCompileCmd
contentDeployCmd
}
productionModeCmd()
{
echo "Changing current Magento env to production ..."
$PHP bin/magento deploy:mode:set production -s
upgradeCmd
diCompileCmd
contentDeployCmd
}
if [ $# -eq 0 ]
then
usage;
else
case $1 in
-h | --help)
usage
;;
-cache | -c)
cacheCmd $2
;;
-reindex | -r_ind)
reindexAllCmd
;;
-upg)
upgradeCmd
;;
-dic)
diCompileCmd
;;
-stcd)
contentDeployCmd
;;
-dev_mode)
developerModeCmd
;;
-prd_mode)
productionModeCmd
;;
*)
esac
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment