31

Why Linux Developers Should Use GitPrompt

 4 years ago
source link: https://www.tuicool.com/articles/hit/ERFZf23
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:

VbARNvf.png!web

“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:

IfE7Jn7.png!web

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:

NFVv6fm.png!web

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”:

EZrQ3e3.png!web

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:

RNFVfui.png!web

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?

NJzeIni.png!web

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.

RnUfIfJ.png!web

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK