Check out a free preview of the full Complete Intro to Linux and the Command-Line course

The "Customize Your Shell" Lesson is part of the full, Complete Intro to Linux and the Command-Line course featured in this preview video. Here's what you'd learn in this lesson:

Brian explains that the prompt is the bit that shows up on every new line, and demonstrate how to customize it.

Preview
Close

Transcript from the "Customize Your Shell" Lesson

[00:00:00]
>> So let's go on to how to customize your shell. Every developer likes to modify their tools and have everything very personalized to what they wanna do. I'm lazy and so in general, trying to use the default for tools, so that when I move from computer to computer that I don't have to customize very much.

[00:00:19]
But I look at some of my coworker's terminals and VS codes, and they have very specific themes, and various specific prompts, and all that sorts of stuff like that. So I'm going to show you how you can start venturing into modifying some of those things. So the first thing that I want to tell you about, there you go.

[00:00:38]
There's the next file that I created. Okay, so next thing I want to tell you about is this prompt, this part right here that you have at the beginning is actually customizable. It's a variable called PS1. So if I say echo $PS1, you'll see that it's this goop right there.

[00:00:57]
And it's telling you the first part is the user, then it has an @, which is this, right? And then it has what the name of the host is, which is probably what all of that is. Then it has a colon, which would be this colon right there.

[00:01:14]
Then the \w is the path that you're in, and then the \$ is actually just literally a $, so that's what that PS1 prompt is. But for this, I can actually say PS1="hello there ". And so you can see there now, my prompt is just hello there, Which is probably not the best prompt.

[00:01:43]
But I've also see people, you can just do this if you want something really simple, right? And now it's just $, it's not busy at all. You can do stuff like put the date in there. But the thing is there's a bunch of customizations you can do for this.

[00:02:03]
But a lot of people have already done this before and made it really cool. And so I've never bothered to figure out the crazy languages that I need to know to customize it, I might just use someone else's. So I'm gonna show you how to do one of the more popular ones, which is called powerline.

[00:02:18]
So I'm gonna say curl, and actually I'm just gonna grab it out of the course notes because I don't want to type this all myself. But we're gonna curl and bash something, I told you not to do earlier, which is in the customizing your shell, this one right here.

[00:02:42]
And we're just going to paste that, so this is gonna go get a installation file off of GitHub. Okay, and then we have tat bash, To .bash, What did they call it? .bash-powerline. So you can see here, this is the long script that it's gonna go and set everything up so that we can have a cool prompt.

[00:03:20]
And so what I'm gonna do now is I'm gonna go into my .bashrc, vi .bashrc. And I'm gonna put another line underneath here. That's gonna be source ~/.bash-powerline.sh. Okay, and now every single time that I start up my bash here, it's going to run this file, which is gonna set my prompt to be something cool.

[00:03:53]
So I'm just gonna run that directly. Now I'm gonna say source .bash-powerline. And now you can see, it's got color. So if I go up a directory, it's gonna do that. If I go back into ubuntu, okay, so right now it looks colorful, and looks a little bit nicer.

[00:04:16]
But let me show you why this actually can be pretty cool. Let's make a director, my-git-project. If I cd into my-git-project, and I do a git init, so then it actually has the name of my branch on here. If I say git checkout -b another-project, it'll keep track of the branch here.

[00:04:41]
I think if I get behind and commits from GitHub, it'll let me know all that stuff. So, it does a bunch of cool stuff like that. The only reason I show you all of this is just to let you know there are other cool prompts out there, and powerline being possibly the most popular one.

[00:04:58]
It would be difficult to say it, but it certainly amongst the most popular one. The one that I use on Mac is one called git bash prompt, which is a good one. It's a little bit more simple, a little less colorful. The one I use for Zsh is called spaceship, which is really cool.

[00:05:14]
So you can check out that one. Yeah, in fact, I'll show you right now. This is one called, Spaceship, and I think it's just for Zsh. But if I go into personal/linux-cli, you can see here it tells me I'm on the master branch. The package is v.1 because it's reading that I have a package.json and it'll tell me.

[00:05:37]
And by the way, you're running node 12.16.0. It puts Kubernetes information in there, it puts docker information in there. It does a bunch of really cool stuff like that.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now