36. Leet Terminal Hacks

Today on the show we will be taking about Leet terminal hack skills. Throughout our working career, we have had to deal with terminal on many occasions and today we will share some of our favorite key bindings and tools that we use to make our lives a little easier in the terminal. There are a lot of things that people don't know about the terminal, including small pieces of incredible helpful knowledge. Inside of this episode we dive into tips on working with the terminal, interesting shell commands or shell applications you can install on your machine, and even how to get out of Vim when you are trapped. All this and more inside today’s episode.

Key Points From This Episode:

  • Matching your terminal configuration across multiple computers.
  • Using DotBot to manage dotfiles in separate locations.
  • The farting goat: finding your terminal prompt.
  • The benefit of taking classes and tutorials; unlocking key features.
  • Understanding and setting up aliases.
  • Z shell and fish shell; weighing up the differences.
  • Kill codes; killing a hanging node server, or Ruby app, etc.
  • Top two feature of Z Shell, and why to use it.
  • Why the terminal may not necessarily be your productivity bottleneck.
  • And much more!

Transcript for Episode 36. Leet Terminal Hacks

[00:00:01] MN: Hello and welcome to The Rabbit Hole, the definitive developer’s podcast in fantabulous Chelsey, Manhattan. I’m your host, Michael Nunez. My co-host today.

[00:00:10] DA: Dave Anderson.

[00:00:11] MN: And our regular guest

[00:00:13] EG: Emmanuel Genard.

[00:00:14] MN: And today we will be taking about Leet terminal hack skills. I imagine throughout our working career, we’ve had to deal with terminal on many occasions and today we'll share some of our favorite key bindings and tools that we use to make our lives a little easier in the terminal.

[00:00:32] EG: Leet elite is a haxor speak for elite for you non haxors out there.

[00:00:39] DA: Yeah and I mean like it's not really elite in any way. Cause I mean, it's like, there are a lot of things that people don't know about the terminal. Like even small pieces of knowledge, like, I remember seeing article recently how the most popular article on Stack Overflow is how do I quit Vim? Like, you just get trapped in Vim by git or some other thing and then how do you get out?

[00:01:07] MN: We're going to teach you how to get out, amongst other things.

[00:01:13] DA: That would be the last thing we teach you. Because by then you will be trapped in Vim. No, just kidding. It's just a colon + Q, guys. Just do that.

[00:01:18] EG: Or, if you want to get super elite haxor, colon + X  will save and quit with one command. 

[00:01:29] DA: Oh, yes, that is a knowledge bomb.

[00:01:32] MN: My, if I want to get out and, like get me out right now, colon + Q, bang! That's no save, I want out. I don't know what the hell I'm doing in here and I need to get out. Q! also known as “bang", will get you right out and everything is under control.

[00:01:51] DA: Yeah!

[00:01:52] MN: And, hopefully production is still available for you online because you didn't make any changes in that file. 

[00:01:58] DA: So, that’s a good start we just solved like half of all terminal questions on Stack Overflow.

[00:02:03] MN: Continue to listen please. I would really appreciate if you listen to rest of the episode.

[00:02:10] EG: Yes.

[00:02:15] MN: Cool, I know one of the things that I find very useful is the ability to share your what's called like the dotfiles or your configuration across multiple computers. Because you have a particular setup at home and you want to share that with your particular setup at work and you want that to kind of match and I was just curious how do you guys manage that aspect of your terminal life.

[00:02:35] DA: Yeah! I've been meaning to do this for such a long time, because I'm always switching between computers for different clients, or for work, or having unfortunate hardware defects on new MacBook Pro's from 2017, god dang it!

[00:02:51] MN: God dang it! Oh, my god.

[00:02:55] DA: So, I had a period where I switch computers like four times in a month and so I finally did it like, just automated the setup.

[00:03:04] MN: Nice.

[00:03:04] DA: And I use this thing called, DotBot.

[00:03:09] EG: Really? Pray tell.

[00:03:10] DA: Yeah. So, basically DotBot is just a simple set of shell scripts that you can extend to manage your dotfiles in a separate place besides the home directory. So that makes it easy for you to commit to GitHub, and also like, it kind of has like simple [inaudible 00:03:34]  based configuration language. So, you don't have to edit all of the hidden files like the files don't need to be hidden. DotBot will just take care of that for you and it can also like move folders over and do all kinds of crazy stuff and it's interesting because you can look at their documentation. They referenced different people who have very thick configuration and you can kind of go and it's like a — it's a book you can look and see what people are using and then, see what you are missing out on. Like what — You can look and see, “Oh why are you using this option? Maybe, I should look at that and try it out?”

[00:04:11] EG: That's really interesting. I have not setup any dotfiles. You know what? I remember first being jealous of someone's terminal setup when I saw a farting goat as the terminal prompt.

[00:04:26] MN: What?

[00:04:27] EG: So, it's an emoji of the farting goat. 

[00:04:29] MN: Oh my god.

[00:04:32] EG: And I was like, “I want a farting goat.”

[00:04:32] DA: Oh this was like a compound emoji. With the passing wind.

[00:04:39] EG: With a passing wind behind her, right? I was like, “That is fire.”

[00:04:42] MN: Yeah!

[00:04:41] DA: Right!

[00:04:44] MN: Yeah!

[00:04:45] EG: And then, 

[00:04:45] DA: Or yeah I think there are some [inaudible + 00:04:47] I've seen that's like there is one in particular that has like chess icons.

[00:04:51] EG: Yeah! 

[00:04:53] DA: I was like, “Whoa! It's so cool.”

[00:04:54] MN: That is pretty dope.

[00:04:54] EG: And so I was like, “Ah, I want to do that,” and then I found Wes Bos who has several like online javascript like classes and tutorials and things like that. He offered like a free Command Line Power User course. And I got to learn what a PS1 was, I didn't know what that was, right? That, which is like the first prompt.

[00:05:17] DA: Oh! Yeah, yeah.

[00:05:17] EG: Yeah, and then, how to set that up so that I can know like what branch I'm on and whether the branch is dirty so I can commit stuff or if there's stuff that needs to stage before I commit on it, to have my name in the project I'm on. All that, it’s stuff that I really like, “Oh! This is like, why haven't I done this before? Because it has all the information you need quickly without having to like, do PWD, which is like Print Working Directory.

[00:05:42] DA: Yeah!

[00:05:44] EG: To find out what's going on here.”

[00:05:42] DA: Yeah. I was pretty stubborn for a while. I was like, “I don't need this. I know a Git status. I know President working directory, like, I know all my commands, I don't need any clutter.” But then like I, you know, when I was digging around the dotfiles a little more, I was like, “Oh, yeah actually there's some really cool stuff out there.” Like, and you can do all kinds of crazy red jacks and colors yourself. Like you can get pretty hands on with it and customize it pretty thoroughly. Or there is a lot of like, off the shelves solutions too for getting your GitHubs or your Git status in the PS1.

[00:06:19] EG: Yeah, and also learning about aliases. That's the first place I really learned how to setup any alias and do that and so now I can just, instead of saying “Git status” I put “GST” and I saved the years of my life.

[00:06:36] MN: Yes.

[00:06:35] DA: Right. You can keep those characters put them in the bank.

[00:06:40] EG: Yes.

[00:06:40] DA: Yeah! Just going back to the Git PS1 thing, there is so many like Stack Overflow posts and different ways to do it. Like, one of the things that I've seen people use a lot is like the helper command utility to get that stuff like, oh-my-git is one I've seen a couple of people use. So that's pretty nice, like very clean and some nice emoji's in there, no farting goats.

[00:07:06] MN: Oh man! You're missing out.

[00:07:06] EG: It needs farting goats.

[00:07:07] MN: Need more farting goats, bro.

[00:07:08] DA: Yeah! Aliases, I've seen a lot of aliases as well. That’s probably the second most or, you know, one of the most common things that people use.

[00:07:20] EG: It can be very personal too. Like idiosyncratic —

[00:07:26] MN: Right!

[00:07:25] EG: — with the person. Like, I use, I think better somewhat standard like, I think GST for Git status and GCO for git checkout are easy to remember. But, you know, if you have someone who has like PWPS2 blah, blah, blah, and its like, “Oh, this thing, like SSH into this box and now I’m in production. Do you want to see production?”

[00:07:46] DA: Right, yeah. Or like, you know, doing an alias for bundle exec as BE, that feels pretty common. But then you can get even further and like bundle exec rails server port 3001.

[00:08:06] EG: Yes.

[00:08:08] DA: As an alias, you know, you're saving those characters, they're in the bank. But, when you actually go and you’re pairing with someone on the same computer then it can be a little bit confusing to follow. It's a bit too much magic sometimes.

[00:08:21] MN: I mean, I often times if I have like those I do have really like gnarly aliases that will help me and my life as I work.

[00:08:33] EG: In your life.

[00:08:36] MN: But I do, that's like one of the things I have to like go over with my pair because I know it could be very abstract. Like, “What did you just do in three letters?” and it's like, “Oh, let me show you my list of aliases,” and what I like to do often times is if I have a pair I try to have the aliases on both machines.

[00:08:55] DA: Oh, yeah!

[00:08:55] MN: So that the person is also aware of the aliases that exists across both machines and we should definitely like, you know, either try to match the same dotfiles like so that we both share the same configurations so there is no like surprises or are we at least have the same aliases.

[00:09:15] DA: Yeah, yeah. Like kind of like the same spirit of like sharing an editor configuration so that, you know, there's no surprises when you're moving from computer to computer.

[00:09:24] MN: Right!  

[00:09:27] DA: Sharing those the same aliases.

[00:09:27] EG: You know, this client I'm on right now and they're onboarding this client gives you a machine and if someone walk you through onboarding getting the data environment setup, it comes with aliases comes with Z shell, well not Z shell like a dash profile about some things already in there. 

[00:09:45] MN: Interesting!

[00:09:45] EG: There is no farting goat prompt.

[00:09:48] MN: Ah! I think you need to BYO.

[00:09:51] EG: But they do have, like the they git prompt that tells you to what branch you're on and whether or not it needs to be, like you have changes in there already.

[00:09:58] DA: That's really interesting. Yeah, that's pretty cool out that they’ve standardized it to that degree. Because you can spend a lot of time filling with that.

[00:10:05] EG: Oh, hours. Easily.

[00:10:06] DA: Yes. I'm not sure they would be like very happy to not have you fiddle on the clock.

[00:10:10] EG: All the time you're saving with the characters you really payback in the time setting that up.

[00:10:16] DA: Right! Yeah! There's a pretty great, I mean there’s always a great xkcd for everything but there definitely an xkcd for that as well.

[00:10:22] MN: I mean like one of the aliases I've seen that has been very helpful I've imagine this exists at your client. Most clients have more than one code base and sometimes you have to switch back and forth from each one. So when its like — like the algorithm, I'm going to say, that I use is like if you want to change from one direct to that directory it will be CD and then like a two or three letter acronym of whatever that project is, right?

So if it's the back end version of the app it will be CDBE. So it’s change directory to the back end and that will — and then I'll make sure that's across every machine so that we all know, “Alright, we need to change at the back end, CDBE boom! And then you’re there. Like, that's my personal favorite way of using aliases.

[00:11:09] DA: Yeah, its pretty useful.

[00:11:10] EG: That is very useful.

[00:11:11] DA: Often like on different computers there is different folder structures

[00:11:15] MN: Yeah!

[00:11:15] DA: And you might not know where its going to be living.

[00:11:16] MN: Yeah. Exactly, that's my-

[00:11:19] DA: My solution to that is normally to use — I forgot what's the name of that utility but I think they just call it jump. So, you can just do [inaudible] install jump and then you just have a J come at end and it does a little fuzzy find on the directories that you've visited before.

[00:11:37] EG: Recently.

[00:11:37] DA: Yeah, yeah. So you can just do like J web and that's your web J core that's your J API and that’s your API or whatever.

[00:11:47] MN: Nice! Pretty Awesome! Yeah, so you guys use Bash as your basic terminal user.

[00:11:55] ED: So, yeah — I first, I was using Bash until I did the Command Line Power User Course by Wes Bos.

[00:12:01] DA: Oh, you levelled up?

[00:12:02] ED: Yes, I levelled up to Z shell.

[00:12:06] MN: Yeah! Alright!

[00:12:06] DA: Oh wait, I feel left out that I'm using bash.

[00:12:07] ED: And, I've heard of fish shell recently too, which I heard is even like, another level up, so.

[00:12:14] DA: Yeah! We should get Zander on here. I know he’s a big fish shell proponent.

[00:12:27] ED: Yeah! That's who I heard from fish shell about, Zander, when I was with him at a client.

[00:12:28] MN: Yeah, I mean, Z shell and fish shell are very similar but I think like fish has like more — like you're able to search through directories better. The way it's configured is very interesting, but I've never used fish. I use Z shell myself.

[00:12:40] DA: But what about Z shell?

[00:12:41] MN: Yeah, I love Z shell. I can talk about Z shell all day. It’s amazing. Everyone who is listening just stop what you're doing and download Z shell with the Oh My Zsh plugin, you can Google Oh My Zsh and it will show you how to install that. It's the best. Like I find, the two things I really like about Z shell, one, is the ability to change directories without having to use CD it's like the best.

So if I want to go three folders up, let's just say, normally in Bash you would have to do CD../../../../.. Nobody got time for that. What, I would do if I wanted to go back I would just do dot dot would go back one folder and I add an additional dot will be the second folder and one more dot will be the third folder. So I can do four dots, boom!

[00:13:30] EG: So you just saved, let me see, a dot and a slash, a dot and a slash-

[00:13:36] MN: No, two dots and a slash.

[00:13:36] EG: Two dots and a slash. Wait, no! Because you still have to say add one dot that you are going back, right? So two dots up you would have two dots and a slash up for the other one, right?

[00:13:45] DA: It's pretty much a third of the character.

[00:13:49] EG: A third of the character, yeah.

[00:13:53] DA: In the bank.

[00:13:56]  EG: Use them for something nice.

[00:13:58] DA: Right. Put your kids through college.

[00:13:56] MN: Exactly, with all them dots that I saved. Another use case that I really like is often times I find myself — I’m going to sound like a murderer, but I find myself killing things, right? Like, when their application hangs in node and you need to kill it like completely.

[00:14:15] EG: Oh, yeah!

[00:14:15] MN: It could be annoying because you would have to deal like PS-A to see the PID and you have to do kill-9 and then put the PID in of whatever you want. Suppose you know that the application you need to kill is a node server that's hanging somewhere. You can literally do kill-9, type “node” and press tab and it will sift through all your PS-A's that have the word “node" on them and then you just select them. You can just select that very one, boom! So, you don't have to look at the — it cuts the process of you having to find that PID to then use it to kill by just searching for nodes. So like if you want to kill a Ruby app, you would do kill Ruby tab and then it will show you all the tabs that are open in Ruby and then you can just go, “I want that one dead, that one dead, that one dead, that one dead.”

[00:14:58] DA: You just used the mouse to interact with that or?

[00:15:02] MN: Well no, you use the tab, you just use the tab. 

[00:15:02] DA: Oh tab, sorry. 

[00:15:05] MN: And the tabbing feature for Z shell is pretty nice too.

[00:15:07] DA: So, it’s just very good auto complete.

[00:15:08] MN: Yes. Yeah, the auto complete is amazing. I think if you have to auto complete between two files and if you're going to like a directory that has like, you know, it can start with ST — Let’s say you're going to the Stride folder, you can do STR and that's the only file that has Stride, it will use that one. But if you had like Stride and string, it will load both of them and then you could tap to the one you want, press enter and then continue on typing the directory you want to go to. 

Oh My Zsh comes with all pretty colors and Github and all that other stuff so you know which one — when you’re in master and when your files are dirty and that kind of stuff. So Z shell is amazing. I really love it and it has all the commands as Bash, so you feel like you know all your Bash commands you can still do them and it won't break as hard. One of the downfall is that a lot of scripts that I've run into at the clients that I have been on will fail miserably on Z shell. So, I have to like swap to bash, run any little scripts that I need to do, and then like switch to Z shell if necessary.

[00:16:10] DA: Oh.

[00:16:14] EG: That's interesting.

[00:16:12] DA: So it’s not fully compatible?

[00:16:15] EG: Are the scripts because they were like the #bang is like usr bin bash or usr bin like?

[00:16:20] MN: Yeah, I think it might the fact that was usr bin bash, which is not like, the Z shell would have his own —

[00:16:26] EG: Yeah.

[00:16:27] DA: — his own usr thing, so then it’s like, “Okay, well,” — and you just type bash. It’s like really easy to jump in and out of bash and Z shell, which is nice too. You can still keep all your configurations the same and if someone is very picky about Bash, you just say, “All right, we're just going to use Bash today,” and just type the word bash, boom! You're back in the Bash shell and you can go by your merry way and then don't worry about it.

[00:16:48] MN: Cool men.

[00:16:48] MN: Let's say Z shell for everyone.

[00:16:48] EG: Cool men

[00:16:49] DA: Emmanuel, do you use anything different in Z shell?

[00:16:52] EG: You know what I'm bad at configuring that stuff. I didn't finish the Command Line Power User by Wes Bos. Once I got, like, the pretty stuff up, I kind of stopped. Like, “Oh, I can see this and I like a farting goat so I don't really care.”

[00:17:07] MN: You just stopped at the farting goat? That's awesome.

[00:17:13] EG: And so, for instance, I remember spending like a good afternoon trying to figure out how to maybe have like setup a bunch of aliases for Git and maybe for a couple of other things. But like after once I got that set up, I like stopped. So I went through getting Git aliases so I won't have to get Git and then I didn't know about the the kill-9, the kill stuff that Bobby just talked about, because that's really cool. Like that say would save a bunch of time, you know, trying to find what to kill when you know something’s hanging somewhere.

[00:17:45] MN: Right! I mean, I think, there are other use cases to find like the PID of an app they are using, but killing things is what I normally use it for.

[00:17:54] EG: That's the only reason I ever need a PID anyways.

[00:17:56] MN: Exactly! Yeah, I mean, I think you use it to monitor certain aspects of the application or know the thread that's is on I'm not getting — I'm all about killing things when it’s hanging and what not.

[00:18:07] DA: Yeah. Yeah, that’s a good point; its really about productivity. So like if you're getting your job done you don't need to get any deeper. It is just fun to like, you know, dig in every now and then.

[00:18:21] EG: You can go really deep. There is a book about the terminal you can find online. I wish I could remember the name, but is like a book that teaches you like all about the terminal and the pitch that the author gives is that this will make you a lot more productive and I don't know terminal is not my bottleneck in productivity.

[00:18:40] DA: Right, right.

[00:18:42] EG: Right? So it's not. Its not my bottleneck in productivity. It is like, “Oh, what should we build?”

[00:18:47] DA: Yeah, right.

[00:18:49] EG: “Should we build this at all?”

[00:18:50] DA: The collaboration aspects, the human aspects.

[00:18:52] EG: Yeah.

[00:18:53] MN: I mean, I think it's really good if you're like an infrastructure engineer who has an SSH into a machine and then you know that they're like the machine that you are SSHing into is a Bash machine you want to be very effective in that. I find myself getting bit all the time when I have to SSH into a machine and I have to do some Vim and then I have to, like I know how to leave Vim that's right. Like everything else in terms of Vim can be really difficult. I'm like, “Oh, what am I doing? I have to hold right so that I can get to the end of the line. When I can press a key, I imagine that sends me all the way to the end of the line.” That kind of thing.

[00:19:28] EG: A, capital A.

[00:19:30] MN: There you go, Capital A will get me there. But like anywhere else if I'm SSHing into a machine, they are like, the Bash commands that I do know to kill or what not are pretty helpful. Unfortunately, you know, I can't SSH into a machine and know confidently that it will be Z shell waiting for me. So I have got to get used to the idea that I have to use Bash everywhere else in the world. But in my own machine I have Z shell and its amazing.

[00:19:56] DA: Yeah. Or you can get the dotfiles and you just pull your dotfiles down.

[00:19:59] MN: Everybody production machine, and every client that I'm on.

[00:20:03] DA: Exactly! Just aggressively. Everywhere you have dotfiles.

[00:20:05] EG: Just using my configuration.

[00:20:06] MN: Exactly, exactly. Oh man. 

[00:20:11] DA: That's good stuff. It's the ultimate hack.

[00:20:11] MN: Ultimately leet terminal hack skills episode that you leave this podcast, just install your dotfiles on every machine that you touch.

[00:20:19] EG: Yeah. It's yours now.

[00:20:26] MN: It's yours now. Cool! I hope that people have learned how to escape Vim and found some really interesting shell commands or shell applications that they can install in their machine and fiddle around with and then create dotfiles so they can spread it across all the other computers that he or she may touch in the workplace.

[00:20:44] DA: Yeah! I definitely learned somethings.

[00:20:46] MN: Oh yeah. Do we have any teach and learns that we want to talk about?

[00:20:48] EG: I would recommend going through the Command Line Power User by Wes Bos maybe the whole thing?

[00:20:54] DA: The whole thing?

[00:20:55] EG: Maybe? Maybe if you want to, I don't know? Until you're like, “I've got my farting goat, I'm good.”

[00:21:01] DA: Right! 

[00:21:01] EG: Yeah!

[00:21:03] DA: So, I've been working a little bit more with GraphQL, which is pretty fun. It's like a coding language to get data out of your API's pretty easily in one go. And, one of the things about GraphQL is that it actually is typed and you actually can generate a schema file out of that. So, for the client that you may use with GraphQL you can get that typed information into your client, which is cool. So you can have some type-checking there if you would like to.

But then also for testing you can mock the API very easily because basically your schema file is an instruction set for your mock library. Like Apollo's GraphQL tools, like has a pretty nice thing that will load up the schema and then just give you back data that looks like your schema when you create it in your tests and, yeah, so I’m digging into that a little bit more and kind of enjoy that.

[00:22:12] MN: Nice! That was cool. I hope to hear some of the things you teach individuals about GraphQL on the later episodes.

[00:22:22] DA: Yeah, sure.

[00:22:23] MN: Awesome! That about wraps up the episode. I like to thank my co-host. Dave, always good having you here. 

[00:22:34] DA: Yeah, fun times.

[00:22:28] MN: And our regular guest, Emmanuel. Always, always a pleasure men.

[00:22:33] EG: It's always a pleasure finding goats.

[00:22:34] MN: Oh, yeah! Farting goats. Feel free to hit us up with your favorite icons and your Bash or Z shell commands, including the farting goat, at twitter.com/radiofreerabbit. This is the The Rabbit Hole. We’ll see you next time.

Links and Resources:

The Rabbit Hole on Twitter

Stack Overflow


Wes Bos

Command Line Power User by Wes Bos


Oh My Zsh plugin