-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_functions
More file actions
53 lines (46 loc) · 1.68 KB
/
Copy pathbash_functions
File metadata and controls
53 lines (46 loc) · 1.68 KB
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
listpath() {
echo "${PATH//:/$'\n'}"
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
parse_git_remote() {
url=`git config --get remote.origin.url`
if [[ ${#url} -eq 0 ]]; then
return
fi
re="^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$"
if [[ $url =~ $re ]]; then
user=${BASH_REMATCH[4]}
fi
echo $user
}
parse_git_fields() {
remte=`parse_git_remote`
brnch=`parse_git_branch 2> /dev/null | tr -d "()"`
if [[ ${#remte} -gt 0 ]] && [[ ${#brnch} -gt 0 ]]; then
printf "($remte:$brnch:"
STATUS="$(git status 2> /dev/null)"
if [[ $? -ne 0 ]]; then printf "-"; return; else printf "["; fi
if echo ${STATUS} | grep -c "renamed:" &> /dev/null; then printf ">"; else printf ""; fi
if echo ${STATUS} | grep -c "branch is ahead:" &> /dev/null; then printf "!"; else printf ""; fi
if echo ${STATUS} | grep -c "new file::" &> /dev/null; then printf "+"; else printf ""; fi
if echo ${STATUS} | grep -c "Untracked files:" &> /dev/null; then printf "?"; else printf ""; fi
if echo ${STATUS} | grep -c "modified:" &> /dev/null; then printf "*"; else printf ""; fi
if echo ${STATUS} | grep -c "deleted:" &> /dev/null; then printf "-"; else printf ""; fi
printf "])"
fi
}
prompt_help() {
echo "";
echo "prompt: (GITHUBUSER:BRANCH:[status])";
echo "";
echo "status characters are as follows:";
echo "";
echo "renamed: >";
echo "branch is ahead: !";
echo "new file:: +";
echo "untracked files: ?";
echo "modified: *";
echo "deleted: -";
}