blob: a302ccc779ace42d92bb5ab6ecc2dc95f2da8b92 (
plain) (
blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#! /usr/bin/env bash
#
# git-sonar
#
# A heads up display for git
if [[ "$OSTYPE" == *darwin* ]]; then
READLINK_CMD='greadlink'
else
READLINK_CMD='readlink'
fi
dot="$(cd "$(dirname "$([ -L "$0" ] && $READLINK_CMD -f "$0" || echo "$0")")"; pwd)"
args=$@
if [[ -z $@ ]]; then
_git="\033[1;30mgit:(\033[0m"
_master="\033[0;37mmaster\033[0m"
_my_branch="\033[0;37mmy-branch\033[0m"
_endgit="\033[1;30m)\033[0m"
_untracked="\033[1;37mA\033[0m"
_added_staged="\033[1;32mA\033[0m"
_modified_unstaged="\033[1;31mM\033[0m"
_local_up="\033[1;32m↑\033[0m"
_2_from_master="\xF0\x9D\x98\xAE 2 \033[1;31m→\033[0m "
_diverged_from_master="\xF0\x9D\x98\xAE 2 \033[1;33m⇄\033[0m 3 "
_not_upstream="upstream \033[1;31m⚡\033[0m "
_detached="\033[0;37mdetached@94eac67\033[0m"
_conflicted_us="\033[1;33mU\033[0m"
_conflicted_them="\033[1;33mT\033[0m"
_ahead_master="\xF0\x9D\x98\xAE \033[1;32m←\033[0m"
_local_diverged="\033[1;33m⇵\033[0m"
_stash="\033[1;33m≡\033[0m"
echo "git-sonar - a heads up display for git"
echo ""
echo "examples:"
printf " $_git$_master$_endgit"
echo " # You are on the master branch and everything is clean"
printf " $_git$_not_upstream$_my_branch$_endgit"
echo " # Fresh branch that we haven't pushed upstream"
printf " $_git$_my_branch$_endgit 2$_untracked"
echo " # Two files created that aren't tracked by git"
printf " $_git$_my_branch$_endgit 1$_added_staged 3$_modified_unstaged"
echo " # 1 new file staged to commit and 3 modifications that we still need to \`git add\`"
printf " $_git$_2_from_master$_my_branch 3$_local_up$_endgit"
echo " # 3 commits made locally ready to push up while master is ahead of us by 2"
printf " $_git$_diverged_from_master$_my_branch$_endgit"
echo " # our commits pushed up, master and my-branch have diverged"
printf " $_git$_detached$_endgit 2${_conflicted_them}3${_conflicted_us}"
echo " # mid rebase, we are detached and have 3 conflicts caused by US and 2 caused by THEM"
printf " $_git$_diverged_from_master$_my_branch 3${_local_diverged}5$_endgit"
echo " # rebase complete, our rewritten commits now need pushed up"
printf " $_git$_ahead_master 3 $_my_branch$_endgit"
echo " # origin/my-branch is up to date with master and has our 3 commits waiting merge"
printf " $_git$_master$_endgit 3$_stash"
echo " # You have 3 stashes stored"
echo ""
echo "usage:"
echo " git-sonar [--zsh|--bash|--fish] [--fetch]"
echo ""
echo " --fetch # Fetches your repo asynchronously in the background every 5 mins"
echo " --zsh # Output prompt using Zsh style color characters"
echo " --bash # Output prompt using Bash style color characters"
echo " --fish # Output prompt using fish style color characters"
echo ""
echo "Bash example:"
echo " export PS1=\"\\W\\\$(git-sonar --bash --fetch) \""
echo ""
echo " This will show your current directory and the full git-sonar."
echo " As an added benefit, if you are in a repo, it will asynchronously"
echo " run \`git fetch\` every 5 mins, so that you are never out of date."
echo ""
echo "Zsh example:"
echo " export PROMPT=\"%1/%\\\$(git-sonar --zsh --fetch) \""
echo ""
echo " Same as the Bash but for Zsh."
echo ""
echo "fish example:"
echo " function fish_prompt"
echo " set_color \$fish_color_cwd"
echo " echo -n (prompt_pwd)"
echo " git-sonar --fish -fetch"
echo " set_color normal"
echo " echo -n ' > '"
echo " end"
echo ""
echo " Same as the Bash but for fish."
exit
fi
while [[ $# > 0 ]];do
command="$1"
shift
if [[ "$command" == "--fetch" ]]; then
nohup $dot/fetch.sh >/dev/null 2>&1 &
fi
if [[ "$command" == "--zsh" ]]; then
$dot/prompt.zsh $args
fi
if [[ "$command" == "--bash" || "$command" == "--fish" ]]; then
$dot/prompt.bash $args
fi
done
|