Skip to content

Instantly share code, notes, and snippets.

@mattbell87
Last active August 4, 2021 00:54
Show Gist options
  • Select an option

  • Save mattbell87/71b9a5aa07b61271ce567ac25851d5ec to your computer and use it in GitHub Desktop.

Select an option

Save mattbell87/71b9a5aa07b61271ce567ac25851d5ec to your computer and use it in GitHub Desktop.
List, search, view and copy woocommerce templates inside a docker container
#!/bin/bash
#
# This script helps with browsing and copying over woo templates from the docker container
#
dockerContainer="your-container-name-here"
templateDir="/var/www/html/wp-content/plugins/woocommerce/templates"
if [ "$1" = "list" ]; then
docker exec $dockerContainer bash -c - "cd $templateDir && find ."
exit
fi
if [ "$1" = "search" ]; then
docker exec $dockerContainer bash -c - "cd $templateDir && grep -rnw . -e "$2
exit
fi
if [ "$1" = "view" ]; then
wooFile=$2
docker exec $dockerContainer cat "$templateDir/$wooFile"
exit
fi
if [ "$1" = "copy" ]; then
wooFile=$2
wooPath="$(dirname "${wooFile}")"
localWooPath="theme/woocommerce/$wooPath"
mkdir -p $localWooPath
docker cp "$dockerContainer:$templateDir/$wooFile" "theme/woocommerce/$wooFile"
exit
fi
echo "DESCRIPTION:"
echo "This script copies a template file from the docker container to the theme directory"
echo ""
echo "LIST TEMPLATES:"
echo "./woo-template.sh --list"
echo ""
echo "SEARCH TEMPLATES:"
echo "./woo-template.sh --search 'searchtext'"
echo ""
echo "VIEW TEMPLATE:"
echo "./woo-template.sh --view path/to/templatefile.php"
echo ""
echo "COPY TEMPLATE:"
echo "./woo-template.sh --copy path/to/templatefile.php"
echo ""
echo "EXAMPLE:"
echo "./woo-template.sh --copy cart/cart.php"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment