forked from acook/git-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_prompt
executable file
·43 lines (34 loc) · 1.63 KB
/
git_prompt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Creates a shiny prompt that integrates well with git
# Load up my script that lets me set colors much easier
source bashrgb
# Load my prompt helpers that make a lot of this voodoo easier to do
source prompt_helpers
# pulls information from git to display in the prompt
git_dirty() {
git status 2> ~/.nil |
awk 'index($0,"Untracked files:") { unknown = 1 }
index($0,"modified:") { changed = 1 }
index($0,"new file:") { new = 1 }
index($0,"deleted:") { deleted = 1 }
index($0,"renamed:") { changed = 1 }
END {
if (unknown) printf "?"
else if (changed) printf "!"
else if (new) printf "."
else if (deleted) printf "-"
}'
}
git_branch() {
git branch 2> ~/.nil | \
awk -v on_color="$(fgc 34)" -v branch_color=""$(fgc 35) '$1 =="*" { printf on_color " on " branch_color $2 " " $3 }'
}
# Set the actual prompt string here
PS1='\[$(title $(PWD))\]$(colorful_hostname) \[$(fgc 32)\]\w$(git_branch)\[$(fgc 32)\]$(git_dirty)\n\[\r\]\[$(fgc 34)\]\$\[$(ansi_reset)\] '
# Pseudocode for new features
# if exists? '.git' then display_git_prompt # speed up the prompt if there's no git repo in this directory
# display_git_prompt() {git_dirty; git_branch;} # Encapsulate the functionality, no point in shoving it all into the prompt string
# git_dirty() { ..code.. unless $1 echo} # adds a linefeed if you are calling it without any args to distinguish between interactive and noninteractive usage
# Extra stuff, maybe use later
#git bookmarks 2> ~/.nil | \
# awk '/\*/ { printf "\033[37;0m at \033[33;40m" $2 }'