forked from diogocavilha/fancy-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.sh
executable file
·222 lines (179 loc) · 5.68 KB
/
commands.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
#
# Author: Diogo Alexsander Cavilha <[email protected]>
# Date: 03.02.2016
#
# Commands manager.
. ~/.fancy-git/modules/update-manager.sh
. ~/.fancy-git/version.sh
fg_script_help() {
sh ~/.fancy-git/help.sh | less
}
fg_show_version() {
local current_year
current_year=$(date +%Y)
echo " Fancy Git v$FANCYGIT_VERSION - $current_year by Diogo Alexsander Cavilha <[email protected]>."
echo ""
}
fg_command_not_found() {
echo ""
echo " $1: Command not found."
fg_script_help
}
fg_install_fonts() {
mkdir -p ~/.fonts
cp -i ~/.fancy-git/fonts/SourceCodePro+Powerline+Awesome+Regular.ttf ~/.fonts
cp -i ~/.fancy-git/fonts/Sauce-Code-Pro-Nerd-Font-Complete-Windows-Compatible.ttf ~/.fonts
fc-cache -fv
}
fg_show_colors_config() {
echo "
git config --global color.ui true
git config --global color.diff.meta \"yellow bold\"
git config --global color.diff.old \"red bold\"
git config --global color.diff.new \"green bold\"
git config --global color.status.added \"green bold\"
git config --global color.status.changed \"yellow\"
git config --global color.status.untracked \"cyan\"
"
}
fg_colors_config_set() {
`git config --global color.ui true`
`git config --global color.diff.meta "yellow bold"`
`git config --global color.diff.old "red bold"`
`git config --global color.diff.new "green bold"`
`git config --global color.status.added "green bold"`
`git config --global color.status.changed "yellow"`
`git config --global color.status.untracked "cyan"`
}
fg_update_app_config() {
fg_create_config_if_not_exists "${1}:"
sed -i "s/${1}:.*/${1}:${2}/" ~/.fancy-git/app_config
}
fg_create_config_if_not_exists() {
local config_content=""
config_content=$(grep -o "${1}" < ~/.fancy-git/app_config)
if [ "$config_content" = "" ]; then
echo "${1}false" >> ~/.fancy-git/app_config
fi
}
fg_show_app_config() {
cat ~/.fancy-git/app_config
}
fg_show_full_path() {
local config_content=""
config_content=$(grep -o 'show-full-path:false' < ~/.fancy-git/app_config)
if [ "$config_content" = "show-full-path:false" ]; then
return 1
fi
return 0
}
fg_show_user_at_machine() {
local config_content=""
config_content=$(grep -o 'show-user-at-machine:false' < ~/.fancy-git/app_config)
if [ "$config_content" = "show-user-at-machine:false" ]; then
return 1
fi
return 0
}
fg_reset_app_config() {
rm -f ~/.fancy-git/app_config
_fg_create_app_config
sed -i '/fresh_file/d' ~/.fancy-git/app_config
}
fg_is_only_local_branch() {
local only_local_branch=$(git branch -r 2> /dev/null | grep "${branch_name}" | wc -l)
if [ "$only_local_branch" == 0 ]; then
return 0
fi
return 1
}
fg_get_branch_icon() {
if fg_is_only_local_branch
then
echo "${is_only_local_branch}"
return
fi
if [ "$merged_branch" != "" ]; then
echo "${is_merged_branch}"
return
fi
echo "${branch_icon}"
}
fg_branch_status() {
. ~/.fancy-git/config.sh
local info=""
if [ "$git_stash" != "" ]
then
info="${info}∿${none} "
fi
if [ "$git_number_untracked_files" -gt 0 ]
then
info="${info}${cyan}?${none} "
fi
if [ "$git_number_changed_files" -gt 0 ]
then
info="${info}${light_green}+${none}${light_red}-${none} "
fi
if [ "$staged_files" != "" ]
then
info="${info}${light_green}✔${none} "
fi
if [ "$git_has_unpushed_commits" ]
then
info="${info}${light_green}^${git_number_unpushed_commits}${none} "
fi
if [ "$branch_name" != "" ] && fg_is_only_local_branch
then
info="${info}${light_green}*${none} "
fi
if [ "$merged_branch" != "" ]; then
info="${info}${light_green}<${none} "
fi
if [ "$info" != "" ]; then
info=$(echo "$info" | sed -e 's/[[:space:]]*$//')
if [ "$1" == 1 ]; then
echo " [$info]"
return
fi
echo " $info"
return
fi
echo ""
}
fg_return() {
local fg_os
fg_os=$(uname)
if [ "$fg_os" = "Linux" ]; then
return
fi
}
case "$1" in
"-h"|"--help") fg_script_help;;
"-v"|"--version") fg_show_version;;
"--colors") fg_show_colors_config;;
"--colors-set") fg_colors_config_set;;
"--enable-full-path") fg_update_app_config "show-full-path" "true";;
"--disable-full-path") fg_update_app_config "show-full-path" "false";;
"--enable-show-user-at-machine") fg_update_app_config "show-user-at-machine" "true";;
"--disable-show-user-at-machine") fg_update_app_config "show-user-at-machine" "false";;
"--config-list") fg_show_app_config;;
"--config-reset") fg_reset_app_config;;
"update") fancygit_update;;
"simple") fg_update_app_config "style" "simple";;
"default") fg_update_app_config "style" "default";;
"double-line") fg_update_app_config "style" "fancy-double-line";;
"simple-double-line") fg_update_app_config "style" "simple-double-line";;
"human") fg_update_app_config "style" "human";;
"human-single-line") fg_update_app_config "style" "human-single-line";;
"human-dark") fg_update_app_config "style" "human-dark";;
"human-dark-single-line") fg_update_app_config "style" "human-dark-single-line";;
"dark") fg_update_app_config "style" "dark";;
"dark-double-line") fg_update_app_config "style" "dark-double-line";;
"dark-col-double-line") fg_update_app_config "style" "dark-col-double-line";;
"light") fg_update_app_config "style" "light";;
"light-double-line") fg_update_app_config "style" "light-double-line";;
"configure-fonts") fg_install_fonts;;
"") fg_return;;
*) fg_command_not_found "$1";;
esac