-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.sh
90 lines (73 loc) · 3.01 KB
/
init.sh
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
#--------------------------------------------
# !/usr/bin/env bash
# @describe: init project
# @author: LHammer(LHammering@gmail.com)
#--------------------------------------------
# set -x
# vim:set ts=4 sw=4 et fdm=marker:
file=./configs/init.ini
source $file
# function initProject {
# read -p "? Enter a project name($name) " val
# projectName=${val:-$name}
# sed -i "" "s/$name/$projectName/g" $file
# mv ./src/app/template/*.tpl ./src/app/template/$projectName.tpl && \
# mv ./src/web/*.tpl ./src/web/$projectName.tpl && \
# mv ../YDTemplate ../YD$projectName && \
# read -p "? Enter your project type($type) " val
# projectType=${val:-$type}
# sed -i "" "s/$type/$projectType/g" $file
# read -p "? Enter ProxyUser($proxyUser) " val
# newProxyUser=${val:-$proxyUser}
# sed -i "" "s/$proxyUser/$newProxyUser/g" $file
# read -p "? Enter ServerPort($serverPort) " val
# newServerPort=${val:-$serverPort}
# sed -i "" "s#$serverPort#$newServerPort#g" $file
# rm -rf .git && \
# git add ./ && \
# git commit -m ':tada:initialization template……' && \
# git pull origin master && \
# git push -u origin master && \
# cd ../YD$projectName && \
# echo -e "\n# ========================"
# echo -e "\x1B[36mproject: { \n name: $projectName,\n type: $projectType,\n proxyUser: $newProxyUser,\n serverPort: $newServerPort\n}\x1B[0m"
# echo -e "# ========================"
# }
# initProject
# echo -e "\n#\033[32m Project initialization finished! \033[0m\n\nTo get started:\n\n \033[33m npm run dev or npm run start \033[0m\n"
function git-branch {
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
}
function git-status {
git status 2> /dev/null | tail -n1 || git status 2> /dev/null | head -n 2 | tail -n1
}
function git-prompt {
local branch=`git-branch`
local git_status=`git-status`
local git_now; # 标示
if [[ "$git_status" =~ nothing\ added\ to\ commit || "$git_status" =~ Your\ branch\ is\ up\-to\-date\ with ]]; then
if [[ $branch == 'master' ]]; then
echo -e "\n\033[33m🚨 WARNING: No permission on branch master, please create a new branch for development~ \033[0m\n"
echo -e "👨💻 Suggest to options:\n"
echo -e "\033[36m $ git co master \033[0m"
echo -e "\033[36m $ git pull \033[0m"
echo -e "\033[36m $ git co -b ${name} \033[0m\n"
else
git add ./ && \
git commit -m ':tada:initialization template……' && \
git push origin $branch
fi
elif [[ "$git_status" =~ Changes\ not\ staged || "$git_status" =~ no\ changes\ added ]]; then
git_now="~ please commit changes not staged"
elif [[ "$git_status" =~ Changes\ to\ be\ committed ]]; then
git_now="* please commit changes"
elif [[ "$git_status" =~ Untracked\ files ]]; then
git_now="+ please commit untracked files"
elif [[ "$git_status" =~ Your\ branch\ is\ ahead ]]; then
git_now="# your branch is ahead, please commit"
fi
if [ "$git_now" ]; then
echo -e "\n\033[31m💥 ERROR: ${git_now} \033[0m\n"
fi
}
git-prompt