-
Notifications
You must be signed in to change notification settings - Fork 0
/
hman
executable file
·199 lines (154 loc) · 4.07 KB
/
hman
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
#!/bin/bash
#
# The MIT License (MIT)
#
# Copyright (c) 2017 Alexandre Magno ‒ alexandre.mbm@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FPS=$(echo "$(ps -o args= $PPID)" | sed "s/^.*\/\([^\/]*\)$/\1/g")
if [ "$FPS" == "gnome-terminal-server" ]; then
[ -n "$*" ] && echo "no parameters please; just 'source hman'" && return
shopt -s cdable_vars
# set vars
export HUGO_PROJECT=$(pwd)
export md=$HUGO_PROJECT
export html=$HUGO_PROJECT/public
which hman &>/dev/null; [ $? -ne 0 ] && PATH=$PATH:$HUGO_PROJECT
# enable the ssh keys in this console
ssh-add -L &>/dev/null; [ $? -eq 2 ] && eval $(ssh-agent -s)
ssh-add -L &>/dev/null; [ $? -eq 1 ] && ssh-add
ssh -T git@github.com # test
return # because we are running directly from Terminal
fi
# TODO fix when executing bash (child) from bash (father terminal)
# TODO [un]install
if [ -z $HUGO_PROJECT ]; then
echo "error: hman is not installed"
exit 2
fi
function show_help() {
echo
echo " hman Points to root"
echo " md To check Markdown, and points to root"
echo " html To check the HTML and enter into it"
echo " commit [message] Commit"
echo
echo " -h | --help Shows these instructions"
echo
}
function untracked_count() {
git ls-files --others --exclude-standard | wc -l
}
function untracked_cd() {
[ $(untracked_count) -ne 0 ] && echo -e "\n > cd $1"
}
function untracked_abort() {
[ $(untracked_count) -ne 0 ] &&
echo -e "\nerror: untracked files \n" &&
exit 4
}
function status_md() {
cd $HUGO_PROJECT
echo
echo "MARKDOWN STATUS"
echo
git status
untracked_cd "md"
echo
}
function status_html() {
cd $HUGO_PROJECT
echo
hugo
echo
echo "HTML STATUS"
echo
cd public
git status
untracked_cd "html"
cd ..
echo
}
function commit() {
cd $HUGO_PROJECT
echo -e -n "\n > "
COMMIT="git commit -a --amend --no-edit";
if [ -n "$1" ]
then
touch commit.txt
echo "$1" > commit.txt
COMMIT="git commit -a -F $(pwd)/commit.txt"
echo "You will commit with message"
else
echo "You will amend"
fi
echo
echo -n "Continue? [y/n] "
read answer
if echo "$answer" | grep -iq "^n"
then
exit 3
fi
echo
hugo
cd public
untracked_abort
echo
echo "HTML STATUS"
echo
$COMMIT
git push -f
cd ..
untracked_abort
echo
echo "MARKDOWN STATUS"
echo
$COMMIT
echo
if [ -n "$1" ]
then
echo " > make \"git push\""
echo
else
echo " > make \"git push -f\""
echo
fi
}
case $1 in
md)
status_md
;;
html)
status_html
;;
'')
echo -e "\n > cd md\n"
;;
-h|--help)
show_help
;;
commit)
commit "$2" # TODO reject $3
;;
*)
echo "error: unknown parameter"
exit 1
;;
esac