git
The Ruby Developer's Command Line Toolkit

Summarized using AI

The Ruby Developer's Command Line Toolkit

Brad Urani • November 13, 2018 • Los Angeles, CA

In the presentation titled "The Ruby Developer's Command Line Toolkit" at RubyConf 2018, Brad Urani shares insights into enhancing productivity for Ruby developers through effective command line usage. He emphasizes the significance of mastering one's shell environment to improve workflow, especially when managing complex Ruby applications at a large scale, as his company, Procore, does. Key points discussed include:

  • Introduction to Dotfiles: Urani explains that dotfiles are configuration files in the user's home directory that allow customization of the shell environment. They enable modifications that enhance how programs interact and overall shell aesthetics.

  • Shells and Terminals: The distinction between shells (like Bash and Z Shell) and terminals is clarified. Urani advocates for using Z Shell for its enhanced features like improved tab completion.

  • Productivity Enhancements: He shares tricks for creating aliases and functions to speed up common command-line tasks, such as a shortcut for 'bundle exec'. Examples include functions for creating directories and simplified Git commands.

  • Utility Tools: Urani introduces tools such as FZF (a fuzzy finder for efficient file searching) and discusses the importance of using editors like Vim, explaining the learning curve associated with it but also its long-term benefits.

  • Git Configurations: The presentation covers how to customize the Git environment through a .gitconfig file, enabling shortcuts and hooks for various Git operations.

  • Customization of Ruby Tools: He discusses improving Ruby development experiences by modifying .irbrc and .pryrc files, which can streamline command usage in Ruby environments.

  • Introduction to Tmux: Urani showcases Tmux, a terminal multiplexer that allows multiple terminal sessions and enhances productivity by keeping sessions alive during SSH connections.

  • Sharing Configurations: The importance of version-controlling dotfiles is emphasized; Urani recommends creating a GitHub repository for easy sharing and management. He mentions tools like RCM and Homestick for symlink management of dotfiles.

  • Encouragement to Experiment: Concluding his talk, he encourages developers to embrace experimentation, highlighting that breaking and fixing their setups leads to valuable learning experiences.

Overall, the presentation serves as a guide for Ruby developers to leverage command line tools and configurations to become more productive and efficient in their workflows.

The Ruby Developer's Command Line Toolkit
Brad Urani • November 13, 2018 • Los Angeles, CA

RubyConf 2018 - The Ruby Developer's Command Line Toolkit by Brad Urani

As a Ruby developer, you use the command line, but do you take advantage of everything it can do? Join us for a demonstration of command line tools for Ruby developers. Increase productivity with search tools, shell functions, git aliases, tmux shortcuts and rbenv plugins. Want a better pry or irb? Supercharge it with shortcuts, macros and gems. Once you've perfected your setup, push it to GitHub so you can pull it and install it on any computer you want. Whether you're a reluctant minimalist or an experienced power user, you'll discover tools to make you a happier and more productive developer

RubyConf 2018

00:00:15.500 Hello, good morning! How's everyone doing? Hmm, oh, be calm.
00:00:22.199 Yeah, my name is Brad Urani. I'm a staff engineer at a company called Procore, located in Southern California.
00:00:27.599 This is what I look like on social media. It's a funny thing: if you do a lot of tweeting and developments and things like that, you're afraid to change your profile photo because you know people might forget who you are. I really should update it, but I was a lot fitter back then, so I might just keep it.
00:00:41.760 Procore is located in a beautiful little surf town called Carpinteria, California, which is about 200 miles north of here. It's sunny and beautiful. We are big supporters of the Ruby community. We're not sponsoring this conference, but we did sponsor the last two RailsConf events, as well as a previous RubyConf. We love these events; if you attended RailsConf, you probably saw our booth and all the engineers we sent down there.
00:01:00.750 We build software for the construction industry, so if you are going to build a skyscraper, a shopping mall, a subway system, or an opera house, there's a good chance you will use our software. It's a full suite of construction management tools for building structures like this.
00:01:13.560 Here’s one of our iPad apps that assists with drawing management for people working in the field. On the side, I mention men because the construction industry, like tech, unfortunately has the problem of being overwhelmingly male. However, we're trying to close the gap with a program called 'Women in Construction' that we designed after several Rails programs aimed at increasing diversity in the tech workforce.
00:01:25.740 Programs like Rails Girls inspired us to create a similar initiative for the construction industry. We are a big Ruby shop, a big Rails shop. We have one of the world's largest Ruby on Rails monoliths. I know Shopify has us beat; they've got like three million lines of Ruby, but we've got at least a million depending on how you count it. It started on Rails 0.95 back in 2005.
00:01:38.700 I know I'm not supposed to tell you exactly how many lines there are, but we have dozens of back-end developers working on it every day. We deploy our code four or five times a day, so we work with Ruby at a huge scale. With massive deployments like this comes a lot of ops work, and that's where tools come into play.
00:01:57.329 I'll be perfectly honest: I'm not very good at this kind of stuff. I'm mostly a web developer, spending a lot of time writing Ruby, JavaScript, and Java, and managing database infrastructure or SQL. However, we have an ops team that handles much of this work.
00:02:07.260 These tools have something in common: they are all very command-line centric. Using these tools effectively requires a good level of competency in your shell. Being comfortable with UNIX-like environments, SSHing into servers, and performing related tasks is essential.
00:02:21.360 When I first entered this world, I was at a bit of a disadvantage. Here's me in 2013; before I transitioned to Linux and Ruby, I did .NET on Windows, so the command line was a little foreign to me. I wasn't immediately comfortable with it.
00:02:35.760 Now, here's me in 2018, and I completely live in my shell! I am in it all day and almost never leave. There's really no difference to me between Windows, macOS, or Linux because I primarily work in my shell. Clearly, something changed in those five years.
00:02:52.280 What shifted was the discovery of dotfiles. Dotfiles are our heroes today! They allow you to customize your shell environment, and that is exactly what this talk is about—how to hack your shell environment.
00:03:06.060 We'll discuss how to customize your shell, install tools, upgrade your shell, and generally make it kickass and awesome by modifying your dotfiles. While this talk is mostly fun and filled with tips and tricks to improve productivity, it carries an important message too. If you gain competency in this environment, it will make you more comfortable using various tools.
00:03:20.950 I like to say that dotfiles are a 'gateway drug' to ops. If you master your shell environment, you won't hesitate to SSH into servers, change configurations, build Docker images, and do various other tasks. It serves as a great segue from a web development career to becoming more comfortable in systems management.
00:03:38.800 So what are dotfiles, exactly? Simply put, they are files in your home directory that start with a dot. If you navigate to your home directory using 'cd ~', you'll see these little files. They customize your system; they change the way programs interact, alter how your shell works, and can modify the colors on your screen. It can be really fun to explore and go deep down the rabbit hole of customizing these files.
00:03:50.800 Now, a word of caution: if you start hacking on your dotfiles, you will break everything at some point and may render your computer nearly inoperable. You might embarrassingly find yourself pair programming with someone and realize you can't run 'bundle install' because you broke something in your .zshrc file. But that's the key—if you embrace learning through mistakes, breaking things, and fixing them, you will ultimately gain the most valuable experience.
00:04:02.670 This process of breaking and fixing is addictive. Here's an actual photo of me on Christmas Eve in 2015. I was supposed to be visiting family in St. Louis, but I got so hooked on modifying my shell environment that I spent most of Christmas hacking on my .vimrc. We drank some red wine together and both passed out.
00:04:16.670 You may miss time with friends and family if you get hooked on this stuff. But anyway, let's start with the shells. We likely all use a shell at some point, and Ruby tools are very shell-centric, as are Rails tools.
00:04:32.780 Let’s clarify the difference between shells and terminals. If you’re on macOS, you load a terminal, such as Terminal or iTerm, which emulates a Linux terminal environment. Inside that, you have a shell where you run commands, and you do have options for shells.
00:04:45.079 By default, macOS and most Linux distributions use a shell called Bash. It’s reliable and well-maintained, but it can be somewhat boring. It turns out you're not stuck with Bash; you can actually change your shell. I use Z Shell (zsh), which is more exciting and offers some additional features.
00:05:01.610 For instance, Z shell features enhanced tab completion with colors and better layouts, which makes working more enjoyable. It still resembles Bash enough that you won't feel uncomfortable if you happen to end up using Bash again. So, it’s nice to have something slightly better without feeling out of place.
00:05:12.450 There are also other shells from the 90s that have fancy visual menus on the screen. I don’t really use them; they seem a little crazy for my taste, but to each their own! You have choices, and I find zsh is a nice balance.
00:05:28.540 To change your shell, you can run a simple command in your terminal. For example, you can type 'chsh -s $(which zsh)', and next time you open a terminal, it will use zsh instead of Bash.
00:05:42.750 This shell also has its own scripting language. Bash and zsh are similar enough that usually, if you write a script for one, you can use it for the other. However, I must admit that these scripting languages are showing their age and have their quirks.
00:06:00.270 For any serious scripting, I would reach for Ruby, as I hope you do too. That said, having a little knowledge about Bash scripting can be beneficial. When you start working on your dotfiles, you might learn just enough Bash to be dangerous, which can come in handy.
00:06:13.630 You can modify how your shell behaves by editing a dot file, specifically your .zshrc file located in your home directory. This is where you can write all sorts of magic that enhances your shell experience. For instance, you can add aliases to simplify commands.
00:06:27.140 I created an alias 'be' which runs 'bundle exec', allowing me to shorten my commands from twelve characters to just two. You'd be amazed at how these small changes can enhance your productivity.
00:06:38.490 Additionally, you can create functions in your shell. For example, I made a function called 'mcd' that creates a new directory while also changing into that directory. It’s a little shell hack that makes your life easier.
00:06:52.120 Another practical function I have is called 'g'. It functions as a shortcut for git commands—if you type 'g' without any arguments, it runs 'git status', but if you give it an argument, it will run 'git' plus whatever argument you provide.
00:07:06.970 This approach indeed speeds up workflow and productivity significantly. Here's another interesting function: if you type 'man', you generally pull up the manual of a certain program. But I’ve overridden that to create a function that gives you colored man pages, which is a nice improvement.
00:07:17.910 You may have noticed my shell prompt looks different from the default. The default is often boring and lacks informative details, so we can enhance it. For example, by adding the current git branch to the prompt, we provide even more contextual information.
00:07:28.000 With my prompt, I can see the current directory, the current git branch, the number of commits behind the origin/master, and the number of unstaged changes. This kind of information is incredibly useful.
00:07:43.320 It took me a while to write the script to customize my prompt, but luckily, I found an open-source project that I could clone and adapt to my needs. It even has built-in features like background fetching and a timeout to prevent freezing if it can't connect to the internet.
00:08:04.050 Now let’s talk about a cool tool called FZF, a fuzzy finder. It makes searching through files much easier and is highly efficient when navigating your command history, making it an excellent addition to your workflow.
00:08:14.540 Now, I know this isn’t a Vim talk, but I want to mention it briefly because of its relevance with dotfiles. Vim is an editor that requires users to learn a lot of unique commands—an entirely different experience from what you may be accustomed to.
00:08:28.440 There are three phases of learning Vim: first, suffering; second, Stockholm Syndrome; and third, the sunk cost fallacy. You may hate it at first, but after investing time in it, you start to appreciate it despite its steep learning curve.
00:08:44.110 Even if you don't use Vim as your editor, knowledge of it is valuable. Remember, Vim on your laptop lays the groundwork for using Vim on servers. You might find it necessary if you ever need to SSH into a server and modify a configuration file.
00:09:00.050 With tools like Psequel, you can customize your experience further. By adding a .psqlrc file in your home directory, you can change your prompt to display useful information and avoid confusing environments, especially when switching between production and local databases.
00:09:14.990 Let's move on to Git. You can configure your environment with a .gitconfig file, allowing you to create shortcuts and customize commands. For instance, I have a shortcut for 'git diff origin/master' which provides colored output.
00:09:28.420 There are also various hooks you can set up in your Git environment that can run scripts automatically during different git lifecycle events, like post-commit or pre-push, allowing you to create more efficient workflows.
00:09:43.420 Now, let's talk about Ruby's capabilities with dotfiles. If you're like me, you Google Ruby Docs quite a bit. To make this easier, you can place certain lines in your .irbrc or .pryrc files to improve your experience.
00:09:53.170 For example, whenever you run tests with RSpec, you can colorize the output or run specs randomly by tweaking your .rspec file. These small enhancements can significantly improve your development experience.
00:10:06.230 You can also modify your Pry interface with a .pryrc file, which allows you to set shortcuts for commands you often use. For example, I have set up 'c' for continue and 'n' for next.
00:10:19.520 Pry also allows you to integrate gems like Awesome Print to enhance the output format, making it clearer and colorized. With these dotfiles, you can transform your Ruby experience immensely.
00:10:29.990 Now let’s talk about Tmux, a terminal multiplexer. The green bar at the bottom of my terminal shows how I can organize multiple terminal sessions and split the view.
00:10:45.290 Unlike terminal applications that can split screens, Tmux allows you to run on a server. For instance, if I SSH into a remote server, I can keep my Tmux session alive even if my connection drops, resuming right where I left off.
00:10:58.890 This functionality is incredibly useful, especially during processes like running a rails console or executing backfills in production. By using Tmux, you gain a layer of redundancy; connection drops won’t interrupt your work.
00:11:12.430 Now that we’ve talked about customization, let’s address how to share your configurations. After creating these helpful configurations, you need to ensure they are saved and can be restored, especially on new machines.
00:11:28.510 To do this, create a GitHub repository dedicated to your dotfiles. This convention—calling it 'dotfiles'—is commonly used. If you want my Tmux setup or my custom scripts, they're public, and you're welcome to explore them and even trade configurations.
00:11:45.000 After setting up your repository, install your dotfiles easily by symlink them back to your home directory. This way, every time you open a shell after setting it up, everything is ready for you.
00:12:02.910 You could use a small program called RCM from Thoughtbot to manage your dotfiles efficiently. It's minimalist yet powerful, enabling you to clone your dotfiles, run 'rcm up', and have your environment set up in no time.
00:12:23.900 You can also find gems like Homestick, which can help create symlinks automatically, or you can even write your own script to manage your dotfiles as you see fit. Learning how to tackle this is a fantastic way to grow your skills.
00:12:40.790 As for whether to fork someone else's dotfiles or create your own, both approaches have their merits. Forking existing dotfiles can provide you with an excellent setup, while creating your own offers a more hands-on learning experience.
00:12:57.590 One quick note: when dealing with sensitive information, always make sure not to check in secrets such as SSH keys or local configuration files into your public repositories. Instead, you can set it up such that your local secrets are loaded only when available.
00:13:14.720 In closing, go experiment! The fun lies not just in having a better environment, but in the thrill of breaking it and fixing it again. This journey often leads to valuable learning experiences with tools like Docker and Kubernetes.
00:13:30.220 Thank you! If you're interested in resources or have any questions, feel free to reach out to me. Also, if you're looking for job opportunities in a beautiful location, we are hiring at Procore and would love to chat!
Explore all talks recorded at RubyConf 2018
+82