-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc_wsl
125 lines (112 loc) · 3.37 KB
/
.bashrc_wsl
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
alias clear='printf "\033c"'
alias ll='ls -l --color'
alias ls='ls -G --color'
alias la='ls -a -G --color'
alias l='ls -al -G --color'
alias lt='ls -alrt -G --color'
alias c='clear'
alias cls='clear'
alias open='cygstart'
alias cdg='cd ~/projectsgit'
export LS_COLORS='no=00:fi=00:di=00;36:ln=00;35:ex=00;92'
export TERM=xterm-256color
function start_visualstudio
{
if [[ $1 != "" ]]; then
cygstart $1
echo "starting visual studio with "$1
return
fi
cygstart *.sln > /dev/null 2>&1
if [[ $? != 0 ]]; then
cygstart src/*.sln > /dev/null 2>&1
fi
if [[ $? != 0 ]]; then
echo "No project file found"
return
fi
}
alias vs=start_visualstudio
# For Bash on Windows
command_not_found_handle() {
if cmd.exe /c "(where $1 || (help $1 |find /V \"/?\")) >nul 2>nul && ($* || exit 0)"; then
return $?
else
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
fi
}
# PROMPT for git
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_BLUE="\[\033[0;36m\]"
MAGENTA="\[\033[0;35m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
function parse_git_branch {
git rev-parse --git-dir &> /dev/null
behind=$(git log --oneline HEAD..origin 2> /dev/null | wc -l)
ahead=$(git log --oneline origin..HEAD 2> /dev/null | wc -l)
git_status="$(git status 2> /dev/null)"
branch_pattern="^On branch ([^${IFS}]*)"
remote_pattern="Your branch is (.*) of"
diverge_pattern="Your branch and (.*) have diverged"
rebase_pattern="You are currently rebasing branch '(.*)' on '(.*)'"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
if [[ ${git_status} =~ ${rebase_pattern} ]]; then
state="${LIGHT_GRAY} ${LIGHT_RED}rebasing${LIGHT_GRAY}"
elif [[ ${git_status}} =~ "Changes not staged for commit" ]]; then
state="${RED}\xE2\x99\xA6"
elif [[ ${git_status}} =~ "Changes to be committed" ]]; then
state="${YELLOW}\xE2\x99\xA6"
fi
else
state="${GREEN}\xE2\x99\xA6"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="${YELLOW}^"
else
remote="${YELLOW}v"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="${YELLOW}^v"
fi
if [[ ${git_status} =~ ${branch_pattern} || ${git_status} =~ ${rebase_pattern} ]]; then
branch=${BASH_REMATCH[1]}
ahead_color=${LIGHT_GRAY}
behind_color=${LIGHT_GRAY}
if [[ ${ahead} > 0 ]]; then
ahead_color=${MAGENTA}
fi
if [[ ${behind} > 0 ]]; then
behind_color=${RED}
fi
echo -e " (${branch} ${behind_color}${behind}${LIGHT_GRAY}|${ahead_color}${ahead}${GREEN})${remote}${state}"
fi
}
function prompt_func() {
previous_return_value=$?;
# prompt="${TITLEBAR}$BLUE[$RED\w$GREEN$(__git_ps1)$YELLOW$(git_dirty_flag)$BLUE]$COLOR_NONE "
prompt="${TITLEBAR}${LIGHT_GRAY}[${YELLOW}\w${GREEN}$(parse_git_branch)${LIGHT_GRAY}]${COLOR_NONE} "
if test $previous_return_value -eq 0
then
PS1="${prompt}: "
fi
}
PROMPT_COMMAND=prompt_func