Mediacurrent

Cracking the Shell

Command line for the Drupaler

Bob Kepford

Lead Architect

Mediacurrent.com

Publisher

TheWeeklyDrop.com

Podcaster

Mediacurrent Dropcast

What is the Shell?

A shell is a user interface for access to an operating system's services.

CLI (command-line interface)

Text command lines

Strengths of the CLI

Light on Resources

Concise

Scriptable for Automation

Weaknesses of the CLI

Commands are not obvious

Not beginner friendly

Why you should learn to use the Shell

It's a Unix system

67.8% to 98.3% of the Servers on the Net are using Unix or Unix like systems

"I have never regretted learning to use a command line tool."


~ Me

CLI's are everywhere

PHP

MySQL

Drupal

Composer

Node

Sass

Scripts / Automation

Customization / Personalization

Make your computer work in the way you want it to.

This is getting serious

.dot files

Configuration files.

Begin with a .

Live in ~

Making the most of Dotfiles

Symlink to a single directory

Track in Git

You can take your customizations with you.

Look at other dotfiles and steal liberally

Add small bits at a time and learn how to use them

Symlink

Pointer to an actual file.

ln -s ~/.source_file ~/bin/dotfiles/target_file

What do you put in your dotfiles repo?

The Shell

Bash:
the GNU Project's shell and is what I use.

ZSH:
a shell designed for interactive use, although it is also a powerful scripting language

Fish:
a smart and user-friendly command line shell for OS X, Linux, and the rest of the family.

Environment / $PATH

Add things to your path


    export PATH=~/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin:/opt/local/bin
    


# Type
    $ someapp
# Instead of
    $ ~/some/dir/drush/someapp.php
    

Aliases

Shortcuts for longer more complex commands.

          
            alias h='history'
            alias l='ls -lhGt'  # -l long listing, most recent first -G color
            alias g='git status'
          
        

Functions

        
          function take() {
              mkdir -p "$1"
              cd "$1"
          }
        
        

SSH

Secure Socket Shell

~/.ssh/config

Save yourself from trying to remember IP addresses and port numbers

      
      Host server1
          HostName    192.168.68.122
          User        napolean
          Port        22
      Host server2
          HostName    192.168.68.123
          User        kip
          Port        22
      
    

Privacy and Security

Don't put sensitive info in your Git repo if you plan to make it public.

Git

Don't use a GUI

Learn to use the commands

Git config

~/.gitconfig

Git aliases

Ignoring files

Per machine: ~/.gitconfig

Per project: .gitignore file in the repository

Per repo: .git/info/excludes

Git Hooks


     .git/hooks
     

Customizing Git - Git Hooks

Pre commit

Code linting.

github.com/andrewmriley/drupal-site-precommit

Post commit

Do tasks like copy your commit message to your clipboard?


#!/bin/bash

# Create dayone entry with last commit message
git log --pretty=format:"%s @${PWD##*/}%n%b" -1 HEAD | dayone new

# Copy last commit message copied to clipboard
git log --pretty=format:"%s %n%b" -1 HEAD | pbcopy

     

But I forget to add those to my repo

.git_template

In your ~/.gitconfig


  [alias]
    init = init --template ~/.git_template

  [init]
  templatedir = ~/.git_template

A good tutorial for setting this up. Logging Git commits with doing

Git tools

Tig

Text-mode interface for git.

Git radar

A more basic tool, vcprompt.

Vim

Why Vim?

I plan on coding for many years.

I'm already in the shell.

Open source and availible on all systems.

Will NEVER die.

I love using the keyboard.

Can Vim do ____?

Yes!

Plugins

ctrlP.vim

Fuzzy file, buffer, mru, tag, etc finder.

Vim Fugitive - Git

A Git wrapper so awesome, it should be illegal.

Gitgutter - Git

Vdebug - Debugging

Vim Plugin For Drupal

drupal.org/project/vimrc

Drush

Download and enable modules

Backup and import databases

Run updates

Watch logs

Log in as any user and much much more!

Drush aliases

Drush commands against a specific Drupal site, even remote sites.

drush @youralias somecommand -y
drush use @youralias
drush somecommand -y

Drupal Watchdog Log

drush ws --tail

Drupal Console

The new CLI for Drupal. A tool to generate boilerplate code, interact with and debug Drupal.

Drupal Console

Debug routes.

Build modules, themes, plugins and more.

Generate content.

Much more.

Tmux - Bringing it All Together

tmux is a terminal multiplexer

Why Tmux

dance fight

Seriously, Why

Detach and attach to terminal sessions without loosing state.

Isolate your terminal sessions.

Script terminal session layout based on project needs.

Tmux

Sessions

Windows

Panes

Tmux Sessions

Tmux Windows

Tmux Panes

Tmuxinator

Create and manage tmux sessions

Projects are Yaml files

Switch projects quickly

Resources

My Dot files

dotfiles - Your unofficial guide to dotfiles on GitHub.

ShellDevel

Craft your own IDE in the shell - Wynn Netherland

Resources

Git

Git Ready

Learn Git branching

Got 15 minutes and want to learn Git?

Git precommit hooks

Resources

Vim

Vim Casts

Boston Vim: Learning Vim in a Week

Let Vim Do the Typing

Vim adventures

VimGolf

Resources

Tmux

Efficient Drupal Development with Tmux and Tmuxinator

Tmux - Upcase - Paid but very good.

A tmux Crash Course

Thank You!

@kepford

mediacurrent.com

TheWeeklyDrop.com