Skip to content

Instantly share code, notes, and snippets.

View KeyboardCowboy's full-sized avatar

Chris Albrecht KeyboardCowboy

View GitHub Profile
@KeyboardCowboy
KeyboardCowboy / aliases.drushrc.php
Last active December 14, 2015 15:49
Drush auto-alias script. This script, when placed in your /etc/drush folder will scan your webroot and auto-detect Drupal installations, both standalone and multisite, and create aliases for each site. It is not complete yet. The grouping still needs a little work, but otherwise gets you off the ground.
<?php
/**
* @file
* Build a dynamic list of drush aliases by identifying Drupal directories.
*
* The script will scan your webroot for Drupal directories. Place this in
* /etc/drush/aliases.drushrc.php
*
* @param $root
* The absolute path to your webroot.
@KeyboardCowboy
KeyboardCowboy / cdd
Last active December 14, 2015 15:49
Quick directory traversal with Drush Aliases and Bash.Do you use drush aliases? Drip this little snippet into your .bash_profile or .bash_rc and start saving bucketloads of time.
###
# Quick directory change for drush.
# While inside a Drupal site, simply cdd to a module or theme by name.
# Add an alias to quickly jump to that site's root or any theme or module within that site
#
# EX.
# $ cdd zen (takes you to zen theme within current Drupal site)
# $ cdd @mysite (takes to you mysite root)
# $ cdd @mysite zen (takes you to zen theme in mysite from anywhere on the server)
##
@KeyboardCowboy
KeyboardCowboy / commit-msg
Last active December 15, 2015 19:19
Automatically add ticket numbers to GIT commit messages using branch descriptions and GIT hooks.
#!/bin/bash
#
# Automatically add ticket numbers to commit messages using branch descriptions.
# Place this file in .git/hooks/commit-msg
#
# Add a description to your branch:
# git branch --edit-description [branch-name]
#
# Mark your ticket numbers anywhere in the description using the following
# syntax:
@KeyboardCowboy
KeyboardCowboy / pre-commit
Last active February 6, 2021 18:09
Check for Drupal Debugging Statements Before Committing Code
#!/bin/bash
#
# Check for debugging statements before commiting your code.
# Place this file in the .git/hooks directory of your project.
# List of function names to search for in regex format
FUNCTIONS='dpm|kpr|qpr|console\.log'
# If any functions are found as executable, prevent the commit.
DIEONFAIL=false
@KeyboardCowboy
KeyboardCowboy / rename.sh
Last active April 5, 2017 18:10
Bulk Rename Files
#!/bin/bash
# File: rename
# Author: Chris Albrecht (chris at lullabot dot com)
#
# Bulk renaming of files.
FROM=$1
TO=$2
FILTER=$3
@KeyboardCowboy
KeyboardCowboy / module_template.install.php
Last active April 5, 2017 18:25
Drupal Update Hook Batch Template
<?php
/**
* Template for hook_update_N() with batching.
*/
function module_template_update_7100(&$sandbox) {
$items_per_loop = 100;
// Initial setup.
if (!isset($sandbox['processed'])) {
// Load the nids to update
@KeyboardCowboy
KeyboardCowboy / commit-msg
Created April 21, 2015 23:10
Blastr Git Commit Message Hook for Jira Comments
#!/bin/bash
# INSTRUCTIONS
#
# 1. Copy .git/hooks/commit-msg.sample to .git/hooks/commit-msg
# 2. Replace the contents of commit-msg with this file
#
# Automatically add ticket numbers to commit messages using branch names.
#
# Branches should be in the format [username]-[issue #]-[short-desc]
#
@KeyboardCowboy
KeyboardCowboy / AwesomeCode.class.php
Last active April 25, 2016 19:24
Drupal module class.
<?php
/**
* @file
* Module class for the AwesomeCode module.
*/
/**
* Class AwesomeCode.
*
* Container class for any custom functionality in the Awesome Code module.
@KeyboardCowboy
KeyboardCowboy / README.md
Last active April 27, 2016 16:30
Local Drush Environment File

Add these files to your ~/.drush directory or your Drupal project.

@KeyboardCowboy
KeyboardCowboy / .gitignore
Last active August 5, 2016 16:44
Keep selected Drupal modules out of PROD automatically with Drush.
# Create a safe space for dangerous modules.
/sites/*/modules/ignored/
/docroot/sites/*/modules/ignored/