how to use the command line to increase speed of development

24
How to Use the Command Line to Increase Speed of Development Dave Myburgh Senior Engineer and Team Lead on www.acquia.com

Upload: acquia

Post on 21-Feb-2017

774 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: How to Use the Command Line to Increase Speed of Development

How to Use the Command Line to Increase Speed of Development

Dave MyburghSenior Engineer and Team Lead on www.acquia.com

Page 2: How to Use the Command Line to Increase Speed of Development

About Me● Dave Myburgh● Team lead for www.acquia.com, training, dev, engage● Most recently worked on docs D6 -> D8 update● 10 years of Drupal● First site in 4.7 and it's still running :)● Started on PC, now on Mac● From DOS to Terminal (autoexec.bat to .bash_profile)

Page 3: How to Use the Command Line to Increase Speed of Development

What we will cover● Pimp out that prompt for Git● Bash profile● Aliases● Drush● File editing● SASS & Compass● Drupal 8 & Composer

Page 4: How to Use the Command Line to Increase Speed of Development

Pimp my prompt● Git on the command line● .git-completion.bash

https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

● .git-prompt.shhttp://git-prompt.shsource ~/.git-completion.bashsource ~/.git-prompt.shexport PS1="[fun_stuff_here]"

Page 5: How to Use the Command Line to Increase Speed of Development

export PS1='[\t]:\w\[\033[0;32m\]$(__git_ps1 " (%s)")\[\033[0;0m\]\$ ';

time path start green

THE MAGIC

end green

For more prompt styling: https://wiki.archlinux.org/index.php/Bash/Prompt_customization

PS1 = main/primary prompt

Page 6: How to Use the Command Line to Increase Speed of Development

Bash profile● .bash_profile on Mac, .bash_rc on Linux● aliases

e.g. alias l="ls =al"● directory listing colors

e.g. export LSCOLORS=GxFxCxDxBxegedabagacad● setting paths to programs:

export PATH="$PATH:/Applications/Dev Desktop/drush"

Page 7: How to Use the Command Line to Increase Speed of Development

Bash profile (cont.)● custom functions

Convert an mp4 video file into an mp3: mp4-mp3() { # ${1%.*} returns only the filename, not the extension. ffmpeg -i "$1" -f mp3 -ab 192000 -vn "${1%.*}".mp3 }

● lots more out there:http://blog.taylormcgann.com/2012/06/13/customize-your-shell-command-prompt

Page 8: How to Use the Command Line to Increase Speed of Development

Bash profile: Aliases● TIP: separate file for aliases, load from .bash_profile

source ~/.aliases

● some of favorites:alias l="ls -al"alias dev="cd ~/Sites/devdesktop/acquiacom-dev/docroot"alias gitb="git branch"alias gits="git status"alias ssh-ac-dev="ssh [user].dev@[server].network.hosting.acquia.com"alias fixwebcam="sudo killall VDCAssistant"

Page 9: How to Use the Command Line to Increase Speed of Development

Drush● The Drupal shell (http://www.drush.org)● command line shell and scripting interface● ships with lots of useful commands● Drupal modules can add more commands

e.g. Backup & Migrate● THE most useful command line utility for Drupal

Page 10: How to Use the Command Line to Increase Speed of Development

Drush (cont.)● Two main ways to get it:

○ Acquia Dev Desktop (Mac & Win)○ install globally for your computer via command line:

$ wget http://files.drush.org/drush.phar$ chmod +x drush.phar$ sudo mv drush.phar /usr/local/bin/drush

● http://docs.drush.org/en/master/install for more help

Page 11: How to Use the Command Line to Increase Speed of Development

Drush (cont.)● Some of the most used commands:

$ drush cc [all] (clear all caches)$ drush dl [module_name]$ drush en [module_name]$ drush updb (run update.php)$ drush sql-cli (login to mysql)$ drush sql-connect (show mysql connection string)$ drush uli [username] (user login)$ drush sa (show site aliases)$ drush @acquia.prod cc all (clear caches on acquia)$ drush up [module_name] (update modules)

Page 12: How to Use the Command Line to Increase Speed of Development

Drush (cont.)● Some Drupal 8 changes & additions:

$ drush cc all (clear all caches) => drush cr (cache rebuild)$ drush dis [module_name] (disable module) => drush pm-uninstall (also used in D7 & below)$ drush config-export / cex (export config)$ drush config-import / cim (import config)$ drush config-pull (copy config to new env)$ drush up drupal!!and many, many more...$ drush $ drush help [command]

Page 13: How to Use the Command Line to Increase Speed of Development

Drush (cont.)● Acquia Dev Desktop:

to avoid this:Command xxxx needs a higher bootstrap level to run...

Page 14: How to Use the Command Line to Increase Speed of Development

File Editing● Vi (Vim), Nano, Emacs, etc.● Personal favorite is nano● Similar commands like DOS editors: Ctrl-[key]● No typing : before commands● Tip: show line numbers all the time (else nano -c)

.nanorc:set const

● Some people use Vim for all editing, instead of an IDE like PHPStorm

Page 15: How to Use the Command Line to Increase Speed of Development

SASS & Compass● Syntactically Awesome StyleSheets● extension of CSS, so regular CSS is 100% valid● get to use variables, nested rules, mixins (functions)● files use .scss extension● create separate files for regions/content types/whatever

and they all get loaded by one file● http://sass-lang.com● https://smacss.com (scalable and modular architecture)

Page 16: How to Use the Command Line to Increase Speed of Development

SASS & Compass (cont.)● Compass is a CSS authoring framework that uses

SASS● provides many useful mixins (functions)● basically, it compiles your SASS files into actual CSS● compass watch will monitor changes to your .scss

files and rebuild the .css file● requires Ruby and a config.rb file in theme folder● http://compass-style.org

Page 17: How to Use the Command Line to Increase Speed of Development

SASS & Compass (cont.)Example: sass/style.scss: @import 'components/base';

sass/components/_base.scss: $blue: #29aee1; a { color: $blue; &:hover { color: darken($blue, 10%); } }

Page 18: How to Use the Command Line to Increase Speed of Development

SASS & Compass (cont.)Example: styles/style.css: a { color: #29aae1; } a:hover { color: #1a90bd; }

$ compass watch (to constantly monitor for changes)$ compass compile (to manually update changes)

Page 19: How to Use the Command Line to Increase Speed of Development

SASS & Compass (cont.)● SO much more...● https://rvm.io/rvm/install (Ruby installation via RVM)● http://www.ruby-lang.org/en/documentation/installation

(regular Ruby install) ● http://sass-lang.com● http://compass-style.org● https://smacss.com

Page 20: How to Use the Command Line to Increase Speed of Development

Drupal 8 & Composer● new way of managing site dependencies● Composer Manager module is a helper module with a

Drupal UI too (requires Composer command-line tool:https://getcomposer.org)

● can replace drush make or work with it● some modules now use composer for their

dependencies - look for composer.json file● https://www.drupal.

org/documentation/install/composer-dependencies

Page 21: How to Use the Command Line to Increase Speed of Development

Drupal 8 & Composer (cont.)● so what's the workflow with composer?● recommended to install composer_manager module,

which will automatically update root composer.json with a module's requirements:$ drush dl composer_manager$ php modules/composer_manager/scripts/init.php

● then download your module(s) and run:$ composer drupal-update

● all dependencies, including core, will get updated

Page 22: How to Use the Command Line to Increase Speed of Development

Drupal 8 & Composer (cont.)● without Composer Manager, you can manually edit root

composer.json to add modules, run composer update to then download the module and its dependencies

● Note: vendor directory will get updated often! Don't worry, those dependencies are restricted to certain versions in core/composer.json, so things won't break e.g."jcalderonzumba/mink-phantomjs-driver": "~0.3.1", (i.e. >=0.3.1 and <0.4)

Page 23: How to Use the Command Line to Increase Speed of Development

Q & A

Page 24: How to Use the Command Line to Increase Speed of Development

Thank You!