Skip to content

Instantly share code, notes, and snippets.

@coreymckrill
Created May 9, 2018 21:55
Show Gist options
  • Save coreymckrill/dd2f40d002d416f3b9296928202ecbc3 to your computer and use it in GitHub Desktop.
Save coreymckrill/dd2f40d002d416f3b9296928202ecbc3 to your computer and use it in GitHub Desktop.
Bash functions for contributing to WordPress
# !/bin/bash
# Apply a Trac patch.
#
# See http://scribu.net/wordpress/contributing-to-wordpress-using-github.html
#
# $1 - The URL of the patch.
# $2 - Optional. Number of leading slashes in the prefix to strip. Default 0.
# $3 - Optional. The VCS to use. 'svn' or 'git'. Default 'svn'.
function tracpatch() {
local url=$1
local strip=${2:-0}
local vcs=${3:-"svn"}
if ! [[ $url =~ ^https://[^\.]+\.trac\.wordpress\.org ]]; then
echo 'The given URL is not for a valid Trac patch.'
return
fi
case "$vcs" in
svn)
curl "${url}?format=raw" | patch -p${strip}
;;
git)
curl "${url}?format=raw" | git apply -p${strip}
;;
* )
echo "$vcs is not a valid value for the VCS parameter."
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment