Skip to content

Commit ead6948

Browse files
committed
[update] : Added some options
1 parent faafe3d commit ead6948

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

tools/msg.sh

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ msg_label=""
1414
label_space="7"
1515
adjust_chr=" "
1616
customized_label=false
17+
nolabel=false
18+
noappname=false
19+
noadjust=false
1720

1821
_help() {
1922
echo "usage ${0} [option] [type] [message]"
@@ -35,6 +38,10 @@ _help() {
3538
echo " -s [number] Specifies the label space."
3639
echo " -x | --bash-debug Enables output bash debugging"
3740
echo " -h | --help This help message"
41+
echo
42+
echo " --nolabel Do not output label"
43+
echo " --noappname Do not output app name"
44+
echo " --noadjust Do not adjust the width of the label"
3845
}
3946

4047

@@ -68,6 +75,13 @@ while getopts "a:c:l:no:s:xh-:" arg; do
6875
_help
6976
exit 0
7077
;;
78+
"nolabel") nolabel=true ;;
79+
"noappname") noappname=true ;;
80+
"noadjust") noadjust=true ;;
81+
*)
82+
_help
83+
exit 1
84+
;;
7185
esac
7286
esac
7387
done
@@ -144,22 +158,32 @@ word_count="${#msg_label}"
144158
message="${@}"
145159

146160
echo_type() {
147-
for i in $( seq 1 $(( ${label_space} - ${word_count} )) ); do
148-
echo -ne "${adjust_chr}"
149-
done
150-
if [[ "${nocolor}" = false ]]; then
151-
echo -ne "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${msg_label}\e[m"
152-
else
153-
echo -ne "${msg_label}"
161+
if [[ "${nolabel}" = false ]]; then
162+
if [[ "${noadjust}" = false ]]; then
163+
for i in $( seq 1 $(( ${label_space} - ${word_count})) ); do
164+
echo -ne "${adjust_chr}"
165+
done
166+
fi
167+
if [[ "${nocolor}" = false ]]; then
168+
echo -ne "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${msg_label}\e[m "
169+
else
170+
echo -ne "${msg_label} "
171+
fi
154172
fi
155173
}
156174

157175
echo_appname() {
158-
if [[ "${nocolor}" = false ]]; then
159-
echo -ne "\e[36m[${appname}]\e[m"
160-
else
161-
echo -ne "[${appname}]"
176+
if [[ "${noappname}" = false ]]; then
177+
if [[ "${nocolor}" = false ]]; then
178+
echo -ne "\e[36m[${appname}]\e[m "
179+
else
180+
echo -ne "[${appname}] "
181+
fi
162182
fi
163183
}
164184

165-
echo ${echo_opts} "$(echo_appname) $(echo_type) ${message}"
185+
echo_message() {
186+
echo -ne "${message}\n"
187+
}
188+
189+
echo ${echo_opts} "$(echo_appname)$(echo_type)$(echo_message)"

0 commit comments

Comments
 (0)