Skip to content

Instantly share code, notes, and snippets.

@davidneedham
Last active April 5, 2016 19:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save davidneedham/4014378 to your computer and use it in GitHub Desktop.
Save davidneedham/4014378 to your computer and use it in GitHub Desktop.
David's aliases and tweaks to the command line that have saved him hours.
#!/bin/bash
#-------------------------------
# Local Development
#-------------------------------
function add_new_host () {
read -p "New local site name: " SITE
HOSTS='/etc/hosts'
SITEPATH='/Applications/MAMP/htdocs/'${SITE}
VHOSTSFILE="/private/etc/apache2/extra/httpd-vhosts.conf"
sudo cp ${HOSTS} ${HOSTS}.original
echo -e '\n127.0.0.1 '${SITE}'.dev' | sudo tee -a ${HOSTS}
echo -e 'fe80::1%lo0 '${SITE}'.dev' | sudo tee -a ${HOSTS}
echo '=================================='
echo 'HOSTS FILE UPDATED'
echo '/etc/hosts'
echo -e "\n<Directory \"${SITEPATH}\">" | sudo tee -a ${VHOSTSFILE}
echo "Allow From All" | sudo tee -a ${VHOSTSFILE}
echo "AllowOverride All" | sudo tee -a ${VHOSTSFILE}
echo "Options +Indexes" | sudo tee -a ${VHOSTSFILE}
echo "</Directory>" | sudo tee -a ${VHOSTSFILE}
echo "<VirtualHost *:80>" | sudo tee -a ${VHOSTSFILE}
echo -e "\tServerName \"${SITE}.dev\"" | sudo tee -a ${VHOSTSFILE}
# Local dev on multiple devices: check xip.io for more information.
echo -e "\tServerAlias \"${SITE}.*.xip.io\"" | sudo tee -a ${VHOSTSFILE}
echo -e "\tDocumentRoot \"${SITEPATH}\"" | sudo tee -a ${VHOSTSFILE}
echo '</VirtualHost>' | sudo tee -a ${VHOSTSFILE}
echo '=================================='
echo 'APACHE VHOST UPDATED'
echo '/private/etc/apache2/extra/httpd-vhosts.conf'
}
function cw () {
echo "bundler exec compass watch";
bundler exec compass watch;
}
#-------------------------------
# GIT
#-------------------------------
# A 'better' git status information
alias gss='git status -s'
# Git add, commit with message, and push
alias gacp=git_add_all_commit_push
function git_add_all_commit_push () {
git add --all;
git commit -am "$1";
git push;
}
#-------------------------------
# Drush
#-------------------------------
#Drush autocomplete
source ~/drush/drush.complete.sh
#
if [ "\$(type -t __git_ps1)" ] && [ "\$(type -t __drush_ps1)" ]; then
PS1='\u@\h \w$(__git_ps1 " (%s)")$(__drush_ps1 "[%s]")\$ '
fi
# Clear the cache and assume yes for all prompts
alias dcc='drush cc all -y'
# Navigate to webroot from any subdir
alias cdd='cd `drush dd`'
# Turn off cache, turn off CSS aggregation, turn off JS aggregation
alias ddev='drush vset cache 0 -y && drush vset preprocess_css 0 -y && drush vset preprocess_js 0 -y'
# From ~/drush/examples/example.bashrc
# # Aliases for common drush commands that work in a global context.
alias dr='drush'
alias dl='drush pm-download'
alias sa='drush site-alias'
alias lsa='drush site-alias --local'
alias st='drush core-status'
# # Aliases for drush commands that work on the current drupal site
alias dis='drush pm-disable'
alias en='drush pm-enable'
alias pml='drush pm-list'
alias unin='drush pm-uninstall'
alias up='drush pm-update'
alias upc='drush pm-updatecode'
alias updb='drush updatedb'
# Download and install Drupal, expects an argument (ie. newdrupal "My Site")
function newdrupal () {
# Create a local variable that is a lowercase version of the first argument.
local lower=$(echo $1 | tr '[A-Z]' '[a-z]');
# Create a local variable that takes $lower and replaces spaces with underscores.
local nospace=$(echo $lower | sed -e 's/ /_/g');
# Download Drupal here.
drush dl drupal;
# Move Drupal to my typical place to put Drupal.
mv drupal-7.* ~/htdocs/"$nospace";
# Navigate to that new folder.
cd ~/htdocs/"$nospace";
# Install Drupal, creating a database along the way.
drush si standard --db-url=mysql://root:root@localhost/"$nospace" --account-name=root --account-pass=root --site-name="$1" -y;
}
# Download and enable a bunch of modules, disable some modules,
function starterdeck () {
# Disable the modules we almost never use;
drush dis color comment dashboard help search shortcut toolbar -y;
# Download our usual modules.
drush dl admin_menu auto_nodetitle backup_migrate botcha calendar checklistapi ckeditor colorbox ctools date devel diff ds entity entityconnect epsacrop entityreference features field_group filefield_sources flexslider fontyourface form_builder google_analytics insert imagefield_crop internal_nodes invisimail libraries link maxlength menu_block module_filter node_clone on_the_web options_element pathauto rc4_email redirect reftagger security_review select_or_other seo_checklist simple_copyright smtp system_stream_wrapper token transliteration vbco views views_bulk_operations views_cache_bully webform xmlsitemap -y;
# Along with some dev versions of modules that have known issues.
drush dl badbehavior --dev;
drush dl moopapi --dev;
drush dl superfish --dev;
# Download the BOTCHA library
drush make sites/all/modules/botcha/botcha.make . --no-core;
# Download unzip and move the Enjoy Creativity Credits module
wget https://github.com/EnjoyCreativity/ec-credits/archive/master.zip;
unzip master.zip;
mkdir sites/all/modules/custom;
mv ec-credits-master sites/all/modules/custom/ec_credits;
rm -rf master.zip;
# Download unzip and move flexslider.
wget https://github.com/woothemes/FlexSlider/archive/version/2.2.zip;
unzip 2.2.zip;
mv FlexSlider-version-2.2 flexslider;
mv flexslider sites/all/libraries;
rm -rf 2.2.zip;
# Download unzip and move colorbox.
wget https://github.com/jackmoore/colorbox/archive/1.x.zip;
unzip 1.x.zip;
mv colorbox-1.x colorbox;
mv colorbox sites/all/libraries;
rm -rf 1.x.zip;
# Download unzip and move wvega-timepicker.
wget https://github.com/wvega/timepicker/archive/1.1.2.tar.gz;
tar -zxf 1.1.2.tar.gz;
mv timepicker-1.1.2 sites/all/libraries/wvega-timepicker;
rm -rf 1.1.2.tar.gz timepicker-1.1.2;
# Download unzip and move superfish.
wget https://github.com/mehrpadin/Superfish-for-Drupal/archive/master.zip;
unzip master.zip;
mv Superfish-for-Drupal-master superfish;
mv superfish sites/all/libraries/;
rm -rf master.zip;
# Download and move libraries for epsacrop.
# # Technique replaced with another less confusing cropping technique
# # See https://www.drupal.org/node/1179172
#wget https://github.com/tapmodo/Jcrop/archive/v0.9.12.zip;
#unzip v0.9.12.zip;
#mv Jcrop-0.9.12 sites/all/modules/epsacrop/jcrop;
#wget https://github.com/douglascrockford/JSON-js/archive/master.zip;
#rm -rf v0.9.12.zip;
#unzip master.zip;
#mv JSON-js-master/ sites/all/modules/epsacrop/json2;
#rm -rf master.zip;
# Adding patches.txt.
mkdir sites/all/patches;
wget -O sites/all/patches/patches.txt https://gist.githubusercontent.com/davidneedham/7061806/raw/269f1c81d3e8555f75c1c5917c37e9fc931a67a0/patches.txt;
# Enable a bunch of the modules we always use.
drush en admin_menu_toolbar ckeditor date date_all_day date_popup date_repeat_field date_tools date_views ds ds_extras ds_forms ds_ui entity entityreference entity_token features filefield_sources form_builder_webform insert libraries link menu_block module_filter redirect select_or_other simple_copyright token transliteration views_ui xmlsitemap_node xmlsitemap_engines xmlsitemap_taxonomy -y;
drush cc all -y;
}
# Disable modules from the starterdeck not used in the training
function training () {
drush dis admin_menu color devel_generate ds entity entityreference insert internal_nodes menu_block module_filter page_manager panels views_content flexslider -y;
drush en comments toolbar -y;
}
# Install drupal AND run starterdeck
alias ndsd='newdrupalstarterdeck';
#(to help me when I want to call it 'new drupal sand box')
alias ndsb='newdrupalstarterdeck';
alias sandbox='newdrupalstarterdeck';
function newdrupalstarterdeck () {
newdrupal "$1";
starterdeck;
add_new_host;
}
# Pantheon has problems with the standard sql-sync. Fortunately there's
# code to make that better. Even more fortunately, it makes most other
# sql-syncs faster + better too:
# https://drupal.org/project/drush_sql_sync_pipe
alias sql-sync='drush sql-sync-pipe --progress';
#-------------------------------
# Other variables and tweaks
#-------------------------------
# Improve ssh with -t for one-off commands
alias ssht='ssh -t $@';
#-------------------------------
# Setting up the console / environment
#-------------------------------
# Allowing iTerm2 to properly update Gems
#export LC_CTYPE="utf-8"
# Changes my prompt
export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
# Makes php in MAMP the default
export PATH="/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.4.4/bin:$PATH"
# Enables coloring of the terminal and colors them specifically
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
# I prefer nano in the terminal
export EDITOR=nano
# Want to use Sublime Text in the command line?
# http://www.sublimetext.com/docs/2/osx_command_line.html
#
# Textmate, Textwrangler, and most others have similar
# shortcuts to open from the command line.
#-------------------------------
# GIT DEV WORKFLOW
#
# These commands all have to do with our development server on its.allgoo.de, which takes advantage
# of the excellent Git Dev Workflow by EOSREI (https://github.com/eosrei/git-dev-workflow). The first
# two commands assume that you have your .ssh/config file set up properly and the last command assumes
# that you have your custom Drush aliases file set up (https://gist.github.com/davidneedham/6301151).
#-------------------------------
# Generate the uli for a particular allgoo.de client site
function gdw-uli () {
ssh -t $1 gdw-drush $2 uli;
}
# Clear the cache a particular allgoo.de client site
function gdw-cc () {
ssh -t $1 gdw-drush $2 cc all;
}
# Refresh an environment on its.allgoo.de
# ex: gdw-refresh projectname dev
function gdw-refresh () {
if [[ $2 == local ]]
then
drush sql-sync @ec."$1".dev @ec."$1".local -y &&
echo 'DB SYNC FROM DEV SUCCESSFUL' &&
echo '==================================' &&
drush -y rsync @ec."$1".dev:%files @ec."$1".local:%files --progress &&
echo 'FILES SYNC FROM DEV SUCCESSFUL' &&
echo '=================================='
elif [[ $2 == dev ]]
then
ssh -t "$1" gdw -y db live "$2" &&
echo 'DB SYNC FROM LIVE SUCCESSFUL' &&
echo '==================================' &&
ssh -t "$1" gdw -y files live "$2" &&
echo 'FILES SYNC FROM LIVE SUCCESSFUL' &&
echo '=================================='
elif [[ $2 == test ]]
then
ssh -t "$1" gdw -y db live "$2" &&
echo 'DB SYNC FROM LIVE SUCCESSFUL' &&
echo '==================================' &&
ssh -t "$1" gdw -y files live "$2" &&
echo 'FILES SYNC FROM LIVE SUCCESSFUL' &&
echo '==================================' &&
ssh -t "$1" gdw -y pull "$2" &&
echo 'GIT PULL SUCCESSFUL' &&
echo '=================================='
elif [[ $2 == live ]]
then
ssh -t "$1" gdw -y pull "$2" &&
echo 'GIT PULL SUCCESSFUL'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment