In a world of beautiful graphical user interfaces (GUI), it can be easy to forget (or ignore) the comparatively ugly and boring command line. However, for those of us who have been doing web development for many years, it is often still our go-to place to get things done quickly without the distraction that a dedicated application sometimes provides. With a little bit of tweaking, the command line can actually look pretty too, while at the same time providing useful information.
In this webinar, Dave Myburgh, senior engineer at Acquia, and team lead on acquia.com, will discuss useful ways to get things done faster by using the command line in Drupal web development.
Attendees will walk away from this webinar with a deeper understanding of:
-Using Git via the command line along with the aid of some visual tweaks
-Managing Drupal sites with drush
-Using SASS and Compass in your themes
-Several small command line tweaks and commands to optimize development
Scanning the Internet for External Cloud Exposures via SSL Certs
How to Use the Command Line to Increase Speed of Development
1. How to Use the Command
Line to Increase Speed of
Development
Dave Myburgh
Senior Engineer and
Team Lead on www.acquia.com
2. 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)
3. What we will cover
● Pimp out that prompt for Git
● Bash profile
● Aliases
● Drush
● File editing
● SASS & Compass
● Drupal 8 & Composer
4. 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.sh
http://git-prompt.sh
source ~/.git-completion.bash
source ~/.git-prompt.sh
export PS1="[fun_stuff_here]"
5. 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
6. 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"
7. 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
8. 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"
9. 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
10. 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
11. 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)
12. 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]
13. Drush (cont.)
● Acquia Dev Desktop:
to avoid this:
Command xxxx needs a higher bootstrap level to run...
14. 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
15. 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)
16. 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
19. 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
20. 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
21. 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
22. 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)