Skip to content

Instantly share code, notes, and snippets.

@csalzano
Created December 3, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csalzano/f54d5d32405fc3cdc5f40addef0c7649 to your computer and use it in GitHub Desktop.
Save csalzano/f54d5d32405fc3cdc5f40addef0c7649 to your computer and use it in GitHub Desktop.
Zips a directory while excluding .git, node_modules, and .gitingore
::plugin-zipper.bat
::Zips a directory while excluding .git, node_modules, and .gitingore
@echo off
set /p slug=Please enter a directory name/plugin slug:
If /I "%slug%"=="" goto earlyexit
tar -a -c -f "%slug%".zip --exclude ".git" --exclude ".gitignore" --exclude "node_modules" "%slug%"
:earlyexit
@csalzano
Copy link
Author

csalzano commented Dec 4, 2020

Usage on Windows

⚠️ Does not work from Git Bash on Windows. Use cmd.exe.

C:\Users\Corey\Inventory Presser\plugins>plugin-zipper.bat
Please enter a directory name/plugin slug:wp-api-manipulate-meta

@csalzano
Copy link
Author

csalzano commented Dec 4, 2020

plugin-zipper.sh, a macOS equivalent

#!/usr/local/bin/bash
#
# plugin-zipper.sh
#
# a script that creates WordPress plugin zip files ready for distribution
# version 1.0.1
#

# perhaps a plugin directory name name was passed as the first argument
if [ -z "$1" ]
then
	# ask the user to type in a site name
	echo "Please enter a directory name/plugin slug:"
	read slug
else
	slug=$1
fi

zip -r "${slug}".zip "${slug}" -x "/${slug}/*.git*" -x "/${slug}/node_modules/*" -x "/${slug}/*.DS_Store"

Usage

[~/]$ bash plugin-zipper.sh inventory-presser

@csalzano
Copy link
Author

csalzano commented Dec 8, 2021

Using git archive could make this platform agnostic https://stackoverflow.com/a/28357990/338432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment