Posted: 2017-09-10 10:16:00
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.
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 https://gist.github.com/alasdairkeyes/0cda5900215295d66e1d217de163ca7e - Just add to your
.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
I'm now available for IT consultancy and software development services - Cloudee LTD.