I can best describe my work environment in three words – git, bash & tabs. While it is important to have a basic level of competancy in bone-stock environments, I am also a firm believer in optimizing my workspace for the sake of comfort and productivity.
I mainly do my git fiddlin’ in bash console. Occasionally, I’ll use GitHub for investigating blames & history crawling. But my exposure & increased competence in git cli has taught me to appreciate a spruced up git config. Tour of my git toolbelt after the break.
Though bash is the core example of minimalist HUD (and simple is güd), I definately feel that a plain command prompt is too bare to productively manipulate & traverse branches.
I don’t know where I am (locally) compared to origin.
This problem really presents itself if/when my local HEAD
has diverged
from a merge conflict, working on out-of-date branches,
or if a collaborator likes to push right before I do.
(I’m looking at you, Montero (ノಥ益ಥ)ノ ┻━┻)
Solution(s)?
- Option 1: $
git status
my fingers numb (yeowch!) - Option 2: Configure a hotkey in
.inputrc
(more on that later…) - Option 3: Setup
.bashrc
to always show a minigit status
Here are some limitations to each though:
- Excessive typing; finger fatigue…
- Commands are now mapped to a hardware-specific input, which may not work when remoting in from another machine.
- Some basic knowledge in shell scripting is required.
Today, Option 3.
Dependencies
- Install git
- Verify files or get them.
- If you see below, you’re good:
1 2 3 4 5 6 7 8 9 |
|
Setup bashrc
Copy into ~/.bashrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Apply changes to current terminal session
$ . ~/.bashrc
Your bash prompt should now look like either of these:
user@host:/home/user/git-path Mon Dec 23 [12:21:43] (master u=)$ _ user@host:/home/user/git-path Mon Dec 23 [12:21:43] (master u=)$ _
And fin. Gone are the days of:
what branch am I on in this window?
(slam out more `git status`)
But kidding aside, this addition to
my prompt has significantly cut down my frequency in calling git status
.
It is totally worth the minimal effort to implement.
Explained
That PS1
looks pretty cryptic, eh? Most of the script is mainly shell script.
You can read more about tweaking bash prompt here.
The secret sauce (and purpose of this post) is $(__git_ps1)
, which comes from
/usr/lib/git-core/git-sh-prompt
. If you’re itchy to customize, I invite you
to read into the file to learn all about git_ps1
’s different settings.
Written with StackEdit.