My New Bash Prompt: Exit Codes, Unicode and Git Branches
I decided to customize my bash prompt. I initially started off with the following requirements:
- It should be two lines! I have found that having the input and my prompt on one line is not enough space most of the time.
- I want to see my current git branch, and also if there are any uncommitted changes in the current branch.
- I want to see my username, host name and current directory.
- The current directory should be truncated so that it shows the 4 closest directories in the path.
- The status if the previous command should be show in some way.
After some work I came up with the prompt shown above. I am excited to keep using it and customizing it, I am also happy that I decided to use unicode in the prompt. I have been avoiding unicode in general, but Rust has convinced me that I should try to accept unicode into my life more readily!
After going through the process, here are sometake aways:
printfsupports unicode more reliably than echo. I had some trouble getting echo to do what I want to do
- I always forget this one. Bash functions are never what I think they are. They are scripts you can define inside of a script. I always seem to find this causing problems for me.
I hope you enjoy! Below is the code for my prompt! Put it into you
.bashrc file depending on your preference. If
you want to use it.
Here is a demonstration video: