Intro to the command line

Post on 02-Jul-2015

478 views 6 download

description

Presented to attendees of RailsGirls Sydney Nov 2013. The command line. Developers' attitudes and common usage. How to improve your experience with it, from a beginner's perspective.

Transcript of Intro to the command line

The Command LineYour next best friend that you kinda still hate

What is it?

• Windows: cmd.exe C:\Users\myusername>

• OSX/Linux: Terminal computername:~ username $

What is it?

What do programmers use it for?

In order of most frequent to least frequent:

git statusgit grepgit diffgit addgit loggit checkoutgit commitgit pushgit pullgit showgit rebase

What else?

rails new myapprails g model Blog title:stringrails consolerails db

What else?

rake routesrake db:setuprake db:migrate

Much Less Frequently

brew install rename # Macgem install railsgem list -dgem list -rbundlervm use 1.9rvm use 2.0

Why should I care?

One year from now you can automate your whole job...

git log $(git merge-base master branch)..branch

cut -f1,2 -d’ ’ ~/.bash_history | sort | uniq -c | sort -nr | head -n 30

wget -mk http://www.stuff.to/read/on/the/train/

rsync -rvP myproject/ username@myhost/myproject.com/

pg_dump --clean -Z 9 app_master | ssh user@apphost ‘zcat | psql -h localhost -U app appdb’

Don’t Panic

Basics

cd projects/railsgirls/ # change into a directorycd .. # get out of a directorypwd # print current directory ls -l # list the files here

!

• Pay attention to the “current directory”

• Press the up and down arrows to run previous commands

• Press tab to complete filenames

Get Unstuck

man wget (spacebar for next page, q to quit)

rails --help

Most reliable: Google “wget command”

Stay FocusedAs a Rails developer, there are only a handful of commands you’ll use regularly.

gitrspecrakerailsgembundleirbrubysubl / vimopensudossh

Next Steps

Incrementally improve yourcommand line capability

git config --global color.ui true

echo "alias ls='ls -ohG'" >> ~/.bash_profile

Shortcuts

up, down, tab

up, down, tab

up, down, tab

up, down, tab

up, down, tab

Ctrl-A start of the lineCtrl-E end of the lineAlt-Delete delete previous wordWorks virtually anywhere! * **

* Terminal, Chrome, Sublime, Evernote, Keynote, XCode, LibreOffice, System Preferences, Gnome, KDE, XFCE4…

** Windows? Not sure.

More Shortcuts

Ctrl-C stop current command (e.g. rails server)Ctrl-R search for a previous commandAlt-B go back one wordAlt-F go forwards one wordAlt-D delete next word

Ctrl-R

1. Ctrl-R

2. Start typing (e.g. type “rebas”)

3. Ctrl-R to jump to next oldest match

4. Ctrl-S to jump to next newest match

5. Return to run, Esc to cancel

Configure Terminal

Configure iTerm2

Text

There Must Be a Better Way!

There usually is

@gregmcintyre microcourses.info