For the past 23 years, I’ve been a Linux developer (I started with Linux version 1.2.1). I live in the command prompt. Because of that, I want the prompt itself to look nice, and to provide useful information at a glance. Therefore, I wrote a script called gitprompt, which customizes the prompt. I’ve been using it at work for a while, and a number of my coworkers noticed it and asked for a copy. So since I know there’s at least some amount of interest in it, I’m publishing this brief article about it, in case you want to try it out for yourself.
Here’s what it looks like, in its most basic form:
“21:53” is the time, followed by my username (“enfors”), and the name of my machine (“shodan”). After that, there’s the current directory — nothing unusual so far. The cursor itself is on the next line to make room for long commands.
So, on to the first feature; if a command fails, the prompt will display its exit status in red so you won’t miss it:
Okay, cool. But why is it called “gitprompt”? I thought you’d never ask. As soon as we cd into a git directory, the magic happens:
Being inside a git directory adds extra information at the end of the prompt; “develop” is the current branch, and “Up-to-date” means that nothing has changed since the last commit. So what happens if we add a file? Let’s find out, by creating an empty dummy file called “foo”:
Now, instead of “Up-to-date,” it says “Untracked”, so we know that there is at least one untracked file in the repo. Let’s track it, by adding it:
Neat, now it says “Added” instead. But what happens if we have both untracked and newly added files? Well, let’s add another dummy file, this time called “bar” to find out, shall we?
I could go on, but I think you get it by now.
If this seems useful to you, feel free to go to the project’s Github page, where you’ll find the installation instructions, and grab your own copy.