-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·181 lines (156 loc) · 5.37 KB
/
build.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
# # /usr/bin/env bash
#
# HZ: Standard Template for bash/zsh developing.
# Version: 20180215
# License: MIT
# Site: https://github/hedzr/bash.sh
#
# Usages:
# $ ./bash.sh cool
# $ DEBUG=1 ./bash.sh
#
# $ ./bash.sh debug-info
#
# $ ./bash.sh 'is_root && echo Y'
# $ sudo ./bash.sh 'is_root && echo Y'
# $ sudo DEBUG=1 ./bash.sh 'is_root && echo y'
#
# $ HAS_END=: ./bash.sh
# $ HAS_END=false ./bash.sh
#
build(){
build_gh_pages
}
publish(){
build
git add . && git commit -m 'build gh_pages'
push_gh_pages_branch
}
get_git_hash(){
git rev-parse --short HEAD | xargs -I % sed -i "s/githash: ''/githash: '%'/g" mkdocs.yml
}
build_gh_pages(){
mkdocs build -v
}
prerequisites(){
git init .
git add . && git commit -m 'zero commit'
git remote add origin git@github.com:hedzr/notes-hi.git
git push -u origin master
}
prepare_gh_pages_branch(){
#prerequisites
git checkout --orphan gh-pages
# git checkout gh-pages
rm -rf ./*
#touch README.md && git add README.md && git commit -m 'initial gh-pages commit'
#git push origin gh-pages
}
init_gh_pages_branch(){
git checkout master
git branch -D gh-pages
git subtree add --prefix=site origin gh-pages
}
push_gh_pages_branch(){
cd site/ && \
git add . && git commit -m 'publish the pages' && \
cd .. && \
git subtree push --prefix=site origin gh-pages
}
#### write your functions here, and invoke them by: `./bash.sh <your-func-name>`
cool(){ echo cool; }
sleeping(){ echo sleeping; }
_my_main_do_sth(){
local cmd=${1:-sleeping} && { [ $# -ge 1 ] && shift; } || :
# for linux only:
# local cmd=${1:-sleeping} && shift || :
debug "$cmd - $@"
eval "$cmd $@" || :
}
#### HZ Tail BEGIN ####
in_debug() { [[ $DEBUG -eq 1 ]]; }
is_root() { [ "$(id -u)" = "0" ]; }
is_bash() { is_bash_t1 && is_bush_t2; }
is_bash_t1() { [ -n "$BASH_VERSION" ]; }
is_bash_t2() { [ ! -n "$BASH" ]; }
is_zsh() { [[ $SHELL == */zsh ]]; }
is_zsh_t2() { [ -n "$ZSH_NAME" ]; }
is_darwin() { [[ $OSTYPE == *darwin* ]]; }
is_linux() { [[ $OSTYPE == *linux* ]]; }
in_sourcing() { is_zsh && [[ "$ZSH_EVAL_CONTEXT" == toplevel* ]] || [[ $(basename -- "$0") != $(basename -- "${BASH_SOURCE[0]}") ]]; }
is_interactive_shell () { [[ $- == *i* ]]; }
is_not_interactive_shell () { [[ $- != *i* ]]; }
is_ps1 () { [ -z "$PS1" ]; }
is_not_ps1 () { [ ! -z "$PS1" ]; }
is_stdin () { [ -t 0 ]; }
is_not_stdin () { [ ! -t 0 ]; }
headline() { printf "\e[0;1m$@\e[0m:\n"; }
headline_begin() { printf "\e[0;1m"; } # for more color, see: shttps://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
headline_end() { printf "\e[0m:\n"; } # https://misc.flogisoft.com/bash/tip_colors_and_formatting
printf_black() { printf "\e[0;30m$@\e[0m:\n"; }
printf_red() { printf "\e[0;31m$@\e[0m:\n"; }
printf_green() { printf "\e[0;32m$@\e[0m:\n"; }
printf_yellow() { printf "\e[0;33m$@\e[0m:\n"; }
printf_blue() { printf "\e[0;34m$@\e[0m:\n"; }
printf_purple() { printf "\e[0;35m$@\e[0m:\n"; }
printf_cyan() { printf "\e[0;36m$@\e[0m:\n"; }
printf_white() { printf "\e[0;37m$@\e[0m:\n"; }
debug() { in_debug && printf "\e[0;38;2;133;133;133m$@\e[0m\n" || :; }
debug_begin() { printf "\e[0;38;2;133;133;133m"; }
debug_end() { printf "\e[0m\n"; }
dbg() { ((DEBUG)) && printf ">>> \e[0;38;2;133;133;133m$@\e[0m\n" || :; }
debug_info() {
debug_begin
cat <<-EOF
in_debug: $(in_debug && echo Y || echo '-')
is_root: $(is_root && echo Y || echo '-')
is_bash: $(is_bash && echo Y || echo '-')
is_zsh: $(is_zsh && echo Y || echo '-')
in_sourcing: $(in_sourcing && echo Y || echo '-') # ZSH_EVAL_CONTEXT = $ZSH_EVAL_CONTEXT
is_interactive_shell: $(is_interactive_shell && echo Y || echo '-')
EOF
debug_end
}
commander () {
local self=$1; shift;
local cmd=${1:-usage}; [ $# -eq 0 ] || shift;
#local self=${FUNCNAME[0]}
case $cmd in
help|usage|--help|-h|-H) "${self}_usage" "$@"; ;;
funcs|--funcs|--functions|--fn|-fn) script_functions "^$self"; ;;
*)
if [ "$(type -t ${self}_${cmd}_entry)" == "function" ]; then
"${self}_${cmd}_entry" "$@"
else
"${self}_${cmd}" "$@"
fi
;;
esac
}
script_functions () {
# shellcheck disable=SC2155
local fncs=$(declare -F -p | cut -d " " -f 3|grep -vP "^[_-]"|grep -vP "\\."|grep -vP "^[A-Z]"); # Get function list
if [ $# -eq 0 ]; then
echo "$fncs"; # not quoted here to create shell "argument list" of funcs.
else
echo "$fncs"|grep -P "$@"
fi
#declare MyFuncs=($(script.functions));
}
main_do_sth() {
set -e
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
trap '[ $? -ne 0 ] && echo FAILED COMMAND: $previous_command with exit code $?' EXIT
MAIN_DEV=${MAIN_DEV:-eth0}
MAIN_ENTRY=${MAIN_ENTRY:-_my_main_do_sth}
# echo $MAIN_ENTRY - "$@"
in_debug && { debug_info; echo "$SHELL : $ZSH_NAME - $ZSH_VERSION | BASH_VERSION = $BASH_VERSION"; [ -n "$ZSH_NAME" ] && echo "x!"; }
$MAIN_ENTRY "$@"
trap - EXIT
${HAS_END:-$(false)} && { debug_begin;echo -n 'Success!';debug_end; } || :
}
DEBUG=${DEBUG:-0}
is_darwin && realpathx(){ [[ $1 == /* ]] && echo "$1" || echo "$PWD/${1#./}"; } || realpathx () { readlink -f $*; }
in_sourcing && { CD=${CD}; debug ">> IN SOURCING, \$0=$0, \$_=$_"; } || { SCRIPT=$(realpathx $0) && CD=$(dirname $SCRIPT) && debug ">> '$SCRIPT' in '$CD', \$0='$0','$1'."; }
main_do_sth "$@"
#### HZ Tail END ####