Skip to content

Instantly share code, notes, and snippets.

@dlnsk
Created April 11, 2024 11:10
Show Gist options
  • Save dlnsk/83dc033129a19e17c5c3208c7fc02f95 to your computer and use it in GitHub Desktop.
Save dlnsk/83dc033129a19e17c5c3208c7fc02f95 to your computer and use it in GitHub Desktop.
The Laradock's helper to run commands inside 'workspace' container
#####################################################
# This is a helper for Laradock (https://github.com/laradock/laradock)
# Allows to run commands inside the 'workspace' container.
#
# Installation:
# Put the file in your home dirrectory or add content to existing one.
# Also you can add content at the end of .bashrc
# Restart console.
# Using:
# Run 'le' from your project's dir and you'll see examples.
# To change the alias just rename function below.
#
# Author: Dmitry Pupinin
# Version: 0.1.0
#####################################################
le() {
help_text="Laradock Exec Helper v0.1
Examples:
$FUNCNAME php -v
$FUNCNAME ./artisan
$FUNCNAME composer install
"
cur_dir_name=${PWD##*/}
project_dir="/var/www/$cur_dir_name"
cmd=${*}
if [ -d "${PWD}/.laradock" ];
then
script_dir="${PWD}/.laradock"
else
if [ -d "${PWD}/../.laradock" ];
then
script_dir="${PWD}/../.laradock"
else
echo "Warning! Laradock is not found for this project."
echo "The '.laradock' directory should be inside or outside current dir."
return
fi
fi
if [ "$cmd" != "" ]
then
(cd $script_dir && exec docker-compose exec --user=laradock workspace /bin/bash -c "cd ${project_dir} && ${*}")
else
echo "$help_text"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment