Development Prompt

Posted: 2017-09-10 10:16:00

Direct Link | RSS feed

I've been looking at a way to streamline my development recently, and I picked up on a couple of problems that I was facing.

  • Git branch tracking - Remembering my current branch and the changes that are outstanding
  • Previous command status - The output from some commands doesn't always make clear if there's been a problem. Typing echo $? afterwards to check the exit status started becoming tedious

I knocked up the following changes to my BASH prompt to help me tackle this.

My prompt now has he following field for previous status.

alasdair@machine (OK) ~ $ 

OK shows that the last command exited with 0

alasdair@machine (OK) ~ $ sdgsdfgsdfhsdfh
sdgsdfgsdfhsdfh: command not found
alasdair@machine (127) ~ $ 

On error the status will be shown instead

In addition, when I'm in a git repository, an extra field is added showing the following


In reality, this looks like so

alasdair@machine (OK) (myrepo.git[master]-1:3) ~/myrepo $

I can see that on the master branch I have 1 modified file and 3 untracked files.

The code to achieve this is in the following gist - Just add to your .bashrc, .bash_profile or whichever file you use to control such things.

If you modify this, make sure that the last_command_status() function is called first, otherwise you'll get incorrect return values being picked up.

If you found this useful, please feel free to donate via bitcoin to 1NT2ErDzLDBPB8CDLk6j1qUdT6FmxkMmNz

IT Consultancy Services

I'm now available for IT consultancy and software development services - Cloudee LTD.