Cracking the Shell – .dot files – The Shell



Cracking the Shell – .dot files – The Shell

0 0


cracking-the-shell

Cracking the Shell: Commandline for the Drupaler

On Github kepford / cracking-the-shell

Cracking the Shell

Command line for the Drupaler

I can't think of many places I'd rather be Feburary than San Diego.

Bob Kepford

Lead Architect

Mediacurrent.com

Publisher

TheWeeklyDrop.com

Podcaster

Mediacurrent Dropcast

Talk about Mediacurrent Talks about TWD Mention Podcast

What is the Shell?

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

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

CLI (command-line interface)

Text command lines

Text command lines.

Strengths of the CLI

Light on Resources

Concise

Scriptable for Automation

  • Light on Resources
  • Concise
  • Scriptable for Automation

Weaknesses of the CLI

Commands are not obvious

Not beginner friendly

  • 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

Unix systems have won.

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

~ Me

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

CLI's are everywhere

PHP

MySQL

Drupal

Composer

Node

Sass

The aren't going away. GUI's are great but CLI's make the world tick. Programming languages have them Popular web services like Github have them. And your computer has them

Scripts / Automation

You're a developer. You can save time and automate the mundane by writing scripts that execute the commands you learn. Make your computer work in the way you want it to.

Customization / Personalization

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

  • Sets up a tmux session multiple widows and split screens
  • Sets up drush alias with drush use.
  • Drupal Console in it's own pane
  • Drush aliases all instances in separate terminal sessions
  • Starts tailing the watchdog for my local dev instance.
  • Starts Vim
If things get serious, what do we do? We put it in Git!

.dot files

Configuration files.

Begin with a .

Live in ~

  • Think of these as your preferences.
  • Dot files are files that begin with a period
  • invisible to file browsers on most systems.

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 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

A Symbolic link is any file that contains a reference to another file or directory in the form of an absolute or relative path.

What do you put in your dotfiles repo?

  • Like my Dentist says, only floss the teeth you want to keep.
  • I put any configuration I care about in it.

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.

I use BASH but there are other great and more powerful and fancy shells like ZSH and Fish.

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
    
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. https://en.wikipedia.org/wiki/PATH_(variable)

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'
          
        
  • a: all except literal .
  • la: List all files long format
  • c: Clears the screen
  • l.: List only dot files
  • l: List files in long human format with time

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.

Include this info in files outside the repo.

Git

Don't use a GUI

Learn to use the commands

Git config

~/.gitconfig

excludesfile = ~/.gitignore Set colors for Git.

Git aliases

git log git lol ##graph git ll adds numstat, number of lines changed git lola same as lol but all branches git lolm just my commit

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.

RSI

Can Vim do ____?

Yes!

Vim is infinitely customizable

Plugins

ctrlP.vim

Vim Fugitive - Git

Gitgutter - Git

Vdebug - Debugging

Vim Surround

Vim Plugin For Drupal

Vim Airline

Vundle - Plugin management

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

Tired of typing the full alias for every command

Now you can just type

Drupal Watchdog Log

drush ws --tail

Drupal Console

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

Download, install, and run Drupal

Drupal Console

Debug routes.

Build modules, themes, plugins and more.

Generate content.

Much more.

Debug routes.

Build modules, themes, plugins and more.

Generate content.

Much more.

Tmux - Bringing it All Together

tmux is a terminal multiplexer What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.

Why Tmux

Seriously, Why

Detach and attach to terminal sessions without loosing state.

Isolate your terminal sessions.

Script terminal session layout based on project needs.

Detach and attach to terminal sessions without loosing state.

Isolate your terminal sessions.

Script terminal session layout based on project needs.

Allows me to quickly switch between projects

Tmux

Sessions

Windows

Panes

Tmux Sessions

Create multiple session

Detatch and reattach

Switch sessions quickly

Tmux Windows

Widows are kind of like tabs.

Create, delete, rename and move them

Tmux Panes

Divides the window vertically or horizontal. Resize and move 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