Monday, October 10, 2016

LA Ruby Conference 2013 Impressive Ruby Productivity with Vim and Tmux by Chris Hunt

up next is Chris hunt
I'm Chris formally square
now off-camera rights formerly UVC at all then
San Francisco who's now a Portland resident I am
there were something else in his bio but it just escaped me so
without on return Chris over to you and who's going to
stop offer the prompt be okay thanks
my name's Chris and I am now living in Portland Oregon as a Saturday
so anybody else from that area please introduce yourself so I can feel to do
there had never been a problem before not so today I'm going to talk about
them anti marks and why you should try it I specially for redevelopment
so anybody are using team t-max who's using T max
not damaged t-max cool was using them okay so when are people using them
so t-max you should try it out using e-maxx
using some other terminal based text editor
yeah I don't think there was one are you are you using
Joe okay I've never even heard that sounds good
okay cool us so let's get started
and we'll start with tea mug so feel free to leave your laptop open if you
wanna mess around that's totally fine I don't mind
also later I'm gonna what you have your laptop %ah been sold
think about that too let's get started with the max per say we're gonna wanna
unless you've been using it you're gonna need to install so
everybody looks like they're on a Mac except for a few folks in you can use
homebrew to do that
so it's going to be brew install team ox
and already have install so it's going in the morning
but that on start for you if you're familiar with laundry know how this
next thing wanna do is create at: marks session
so how to mix works is it the server that runs on your machine
your terminal axes a client an incorrect as many clients as you want
why might you want to use t-max wise re developers with a ton of turmoil based
applications already right we use get
we use what I see is bundler rpm rake
I we use are rails console louisiana
database console open were SSH into a bunch machine so we pretty much
live in the terminal it makes sense that you want to use a text editor that in
the terminal as well thats
were been comes into play anti much is something you can use to you can manage
all of those applications
so it gives you sessions that you can create for each of your applications
to hold other services together and then you also have
windows and pains and other organizations also if we start a team
it'll look like this we duty marks new session and you can do just knew for
and we're gonna name this LA Ruby cool
does deluxe who super easy so if you look at the bottom
corner here on this is going to be that the status bar in the bottom corner is
the name
and in the right-hand corner we had other things like this is my hostname
date and time the status was completely configurable
anything you can run in the terminal you can stick its output in that status bar
so you can do things like
sports scores the weather see i status whatever you want I had to keep it super
simple down here
on you have a number a keyboard shortcuts
too much provides Help menu for you that lists all yours
keyboard shortcuts this includes also the custom circa you've configured
if you wanna see Mighty Muggs configuration like this simple
status my head down here and other a hockey's I have
that is on get home and it's going to be at this
URL I'll give you a few seconds to write this down just because they don't have
slides coming upload later I'm getting a lot urals by the way so you know and
have something if you're at all interested
in this kinda stuff cool
I so let's get started on this is gonna come to show how too much works if you
look into
very bottom here you'll see we have one window we can create
new windows so now we've got four different windows open
we can rename our windows like I'm gonna call this one oh hello
I'm gonna go back to our first 10 and call this world
and the state the window is saved so we can just gonna do whatever stuff we want
to go back and forth back and forth
inside a window we can create multiple panes
like that and we also again have multiple sessions where we can
redo all this stuff again at the nice thing about all the stuff on doing with
the MUX
is you don't have to use keyboard shortcuts you can also use the team
looks command to do it so if you go to a new window
and eyesight t-max split window
it's what's the window so this might seem super silly cuz you can you do
she's gay or circuits right
but this allows you to script everything that he mocks can do
so if you have are multiple Rails project that all have different
something you wanna run that you can actually script that behavior so let's
see how that works I'm just going to you
detach from this session says your status bar when away we're no longer in
T marks
and I'm gonna go into a rails app that I have my awesome app
and in here I have a team ok script ready to go
so we can see what one might look like down
first thing it's gonna do create a new session called my awesome app
in that session it will create a new window called server
and start a real server for us and it will also create another 10 called them
and start them the last thing it's going to do here is just attached to that
so give it a shot quit notes
and run
that so we're done so looking in the corner we have are my awesome app
and we have our three panes their first pain being our
terminal session the second pain being are real server that's already running
for sale
and then Arthur bang being them if we look at our session list
you can see the first session is still here and we can go back to it
or we can go back to the second session started
prequel I'm I never uses behavior I never skip to Moxie
I personally like to have just one session and I have all my windows down
so in I turn to you there's a really nice thing you can do here
in your preferences
profile general down here on
t-max there's a cent except start
every time you start terminal it's going to send this text your terminal so I'll
I prefer to start
a accession and if that session already exist
just attach to it this way every time you open your terminology resume reelect
if you like mean you quick I term accidentally all the time you'll never
lose your work
because it's going to be running in the background
okay so now and then so let's talk a little bit about something stuff
there are several now smaller plugins I like to use
for didn't help me with a Ruby on Rails development
so now we're in a Rails apso will look at some respondents on the first day
because real says it on a files we're gonna need a nice way to search
for files so I something called control P
and that pulls up a nice menu here and this is a fuzzy search
so anything you type is gonna just near the filter a file so by type
I'm gonna look for my application control or so by tight a
and then I type C for controllers in an Italian
okay so now we're down to application controller and I could press Enter
and i cant open it on this is control P super useful
on the URL for control P is here it's on get up
you could probably just google that too you're right down
the next useful plugin is for searching within file so we know how to find files
and the nexus of organizers for searching across files for something
like seven wanna find were a method is to find a way
class is defined as something we do all the time right and there's a
plugin called AG and AG works exactly like crap
except it has some additional configuration options so again looking
in the corner
the way that works is all the command use enter gonna be down here in the
corners is
like this command line I'm using AG here and I'm gonna search for
my awesome application
or my knee awesome
ap ago so now we see in this pain here all the results and we can just kinda
look at them
open them in the top pain go back down find a different one
open on so this is also extremely useful for searching to retire project
great so let's open up my Gemfile
do more things on a show you never gonna move on to something cooler promise
on this is my Gemfile as you can see everything in here has single quotes
except for MySQL like the gym for some reason has double quotes
don't know why but it really bothers me so what I like to use
is something called surround that makes really really easy to change
surrounding characters and you can do this for anything like changing trying
to seize two brackets
double quotes to single quotes squiggly brackets to straight lines whenever you
want or even tax it supports HTML tags
on things like that so for example we want to change the double quotes
to single quotes studies so again
I'll show you with the us like an array example
now we can changers surrounding
to parentheses
to okay so surround
can be found
sir around here also and get up and this is by Tim Pope who has
a tonic very very useful I'm done plugins
cool the last plugin I wanna talk about
is something I use all the time and maybe some people never use because this
is just something that I found
I'm picky with and people other than me don't really care about and that is
aligning stuff
so in this gym file issue we have two gyms here
and both upon refer to a git repository and
what I like to do is align my house rockets house like the line stuff that
our it I'm a very visual person I T line stuff so there's a great Gen that helps
you like anything
and that's called tabular zone this case I just want to align
those to get characters I'm so it looks pretty so again looking down at the
I'm running commands I'm gonna run tabby lives and I'm gonna match
get and this works with any regular expression
and align those things see a scene out the to get the gets our lives so
if you have save 50% on hash that's where this really becomes useful if you
want on-line als or hash rockets
or something like a Gamma Phi lower HTML things like
cool so I am now done with israel's up
so we can detach from the session and I'm going to spend a little bit i'm
talking about. on
test driving something in them at this is really easy to do and then
we never need to leave them we can keep running our test within them and go back
and forth between file so it's it's really cool
so we're going to add a and is everything from my with the math
library I'm I mean why people have never actually used it but really has dared
math library has
square root cause and sign on stuff you never actually is we're going at a
summit it to that
so it's really complicated wanna make sure we have tests
so we are going to go into our math directory I'm going to create
to directories here I'm in a great live which is we're gonna put our code
and spec which is we're going to put our tests
and then like any good review developer also we have a jump i'll
source is going to be rubygems
and all we need is r-spec
I okay great now it's time to bundle
again paying attention to the bottom corner we can run bundle right within
their egos come
big money big money wake up my phone
and what's the question
this is in this is it what's happening is damage is going to the background
so it's like if you do controls the it'll send it to the background and you
can type
for grounder ft to get back in the foreground so this just send
them to the background it's running the command now that it's done at the bottom
here to ask me to press ENTER and then she's gonna pop them
back up for us yep so we don't need to open up
a separate window or anything like that we can run any show command from within
annexing wanna do now is writer test so we will add again
at the bottom you become very familiar with the bottom love them window
we're going to open up aspect while so we're going to open up spec
and we're gonna say math spec Darby we are going to require our math library
that does not exist yet
and then we are going to describe math more subjects
will be math taping is hard
and they were going to describe some
and then
its and adds
to numbers now we can actually read our tests
subject dot some one and 11
should equal 12 and one more tests to make sure we don't cheat
subject outline see
-1 5 should
equal for cool
so now we have two tests and we can run them right within them
so in in mind Mr C which I'll share with you and
and which I stole from Gary burner and you can press I
comity would com is my leader key meaning it's the key to them recognizes
a key SN to do actions I can you comity and it'll run my test
I'm so in this case will see at the very top we have our first failure that says
he can't find the file math that's cuz we have created
so we can do we can open that file so again at the bottom I'm just gonna open
up math
Darby we could save it and run our tests them is gonna remember the last test we
so we can go from father father filing keep running the same test orient okay
can't find some
great at it so we have I module
math and thus
is rugby class method so we can do extend self and we can do some
left right runner test again
all rights we have different failure it expects 12 in a got no
so we can return 12 K
Ryan an
and okay so now at the bar actually break code and i actually
don't know how to rate this code so I'm going is out this actually always
happens to me when I write s
aided by Ray have to record I don't know what to do so okay so
now and like I said this actually does happen me all the time
I don't know how to read the code in response to write so I asked for help a
nice way to do that
is to make it just the problem sure somebody
so we're gonna see how to make a just from them I'm going to open
my spec file again cuz that's probably what I want to share and is gonna say
hey can you guys know how to make this test pass
so let's open that up spec and the commander morning at the bottom here
is just see if this works Rai
so we just made a gist from them yet it's used right
and actually do anything at the plugin again another plugin surprise
I don't like a lot of plugins but the ones I do you say he's every single day
and so we now have I a jest let me share the URL for this
few seconds
this is really easy to set up it ask your credentials one time in and saves
token it doesn't save your password cool so like I said usually I would just take
this URL it may be stored on Twitter
are sent an email to somebody in or something like that but I wanted to take
the entire room re people here and I'm sure somebody knows how to make this
test pass
I does anybody know how to make yes anybody
we I'm seriously asking the question could somebody please tell me
director says best nobody
I'm on my own hi guys want to pair
so here is a man alright
I will give a demonstration from my laptop me pairing with myself
okay area
okay I'm gonna give it their all the pairing with myself guys you're killin
okay so I just share the URL simply gracefully volunteered
and to help me and now I'm going to create and a share team accession
so by default almighty muck sessions are hidden
art everybody else on the system it's just a privacy thing we don't want
people be able to see what I'm working on
some degree a new team accession anybody else can connect to
and they will both be able to work on the same problem so by quick out of here
I'm gonna clear screen and I'm going to you
store a team accession in 10
pair and
new I'm going to name this session math
cool sold now it's running I'm going to change the permissions on
so that anybody can access it and now I'm going to attach myself
to that session school
so now ur in our intimate session anybody else on my computer can connect
summary open our project
and your spec open and rewrite just to make sure story left off
good and rerun artists here
okay so now I'm ready to have somebody else
happened to my system so what I would have them do is I would share with them
I would really trust them because I'm allowing them to connect to my machine
I would ask them to SSH into my machine once the SSH 10
they can run that same team UKs attach command Iran to connect to the session
that we're working on here
so I can actually open up a different terminal here is gonna be a much smaller
but you can probably see what I'm doing here
I can reattach temp
pair and attach
and now I have to terminal sessions connected to the same
d Mike session ancestral just a quiet when can I any number we want they can
go ahead
and right the code that makes a pass and we can rerun it s
and we see passes so this is a really cool way
to pair program with people that you're not sitting right next to you
okay have you time doing good
so I have one more very cold in thing on a show you
we are back in our session that we had later this is the my awesome app session
the big Rails app
on this is our a nice refactoring tool something has something called
Rd West which you can stick any files you want into it
it's just basically an array a file names and you can use any terminal
command to generate that
a ref file name so you saw we used the ag2r earlier
if we do a search across a Rails project
for an again for that constant so we do Agel
my awesome ap you see that we just get a list of all the file names
that contain my awesome app so this case
we want to replace our application constant with
to do ap because we decided we're actually gonna give it a proper name in
it's a to do out so to do that we can use our card list
so again paying attention to the bottom here now we are going to Brian
arts and then we can run the same AG command to grab all those file names
sorry not for my awesome ap ever gonna do it our current directory
and then we press better obliterate
you again press Enter we now
get the worst up
all the files that contain this match and it's loaded in our glist
so now that them is aware of what files are going to be working on we can tell
to run whatever we want across the files
so again looking at the bottom I'm gonna run arc do which means do this for every
single file
I'm gonna search for my awesome
an app and I'm gonna replace it with to do ap
and I'm putting GC because I wanted to do it globally across the whole file
I wanted to can't make a confirmation on each search our place
and then after I do that I'm gonna wanna write the file so when i press ENTER NOW
its gonna probably on every change and I can just keeping why why
wines can look at every single file do the search
it good good done so it's super easy
I didn't really know about arcs Intel couple months ago but now I use it every
very useful we could do more then a search our place though
on his AB Schirmer with the macros know how those work
nobody cool so been macros basically a
just wave recording everything into a buffer and dams you can
OnStar macro do all that you have a key strokes and stop the macro
and rerun over and over and over again we can actually do our macro cross
our files as well which means we can do anything across all our files
so I wanted to add my name to the top of all these files
I can record a macro that does that so I will start recording a macro
I will go to the top of my file I will add a comment that says by
Chris hearts cool
and dance stop recording my macro
and then just to make sure my macro works im gonna delete that heading and
run my macro again
okay so I've got a macro recorded now I'm just can use argue again
at the bottom are do and I'm gonna rerun at macro cross
all the files are in the buffer so I can do norm which says pretend like I'm
typing and I can do command Q
and enter cool also just ran the Mac across
all the files very cool and with thats
I'm going to take questions you have any questions
about them at: max yes front now actually the
plugin to support that I don't know how to do it but it does
like it really does so the question was is there anyway what you published just
at the gist
back within them and you can yeah it uses
just uses the just API so does everything the EP I can do yes
so the question is when you're doing like pairing with the monks to see what
I'll act like you might see with the screen showing and no you don't
it's just like if u SS aging is exactly the same if you SSH into a box
and you type its pretty fast I mean you can experience like right but its
much faster than screen sharing not sending you know pictures back and forth
your questions cool
thank you alright that's it