Skip to content

Commit ec59e08

Browse files
leaned up some of my code
Signed-off-by: The-Repo-Club <wayne6324@gmail.com>
1 parent e9d779b commit ec59e08

1 file changed

Lines changed: 125 additions & 120 deletions

File tree

proctl

Lines changed: 125 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# GitHub - https://github.com/The-Repo-Club/
66
# Author - The-Repo-Club [wayne6324@gmail.com]
77
# Start On - Fri 18 February 2022, 07:26:28 pm (GMT)
8-
# Modified On - Tue 22 February 2022, 09:58:45 pm (GMT)
8+
# Modified On - Tue 22 February 2022, 10:49:20 pm (GMT)
99
# -------------------------------------------------------------------------
1010
#
1111
#
@@ -127,23 +127,23 @@ make_new_config() {
127127
#=== DEFAULT CONFIG ===========================================================
128128

129129
read -d '' <<-EOF
130-
#!/usr/bin/env sh
131-
export AUTHOR_NAME='$(git config user.name || echo "${USER}")'
132-
export AUTHOR_EMAIL='$(git config user.email || echo "${USER}@gmail.com")'
133-
export AUTHOR_WEBSITE='https://example.com/'
134-
export AUTHOR_GIT='http://github.com/$(git config user.name || echo "${USER}")'
135-
export LICENSE_DIR='$LICENSE_DIR'
130+
#!/usr/bin/env sh
131+
export AUTHOR_NAME='$(git config user.name || echo "${USER}")'
132+
export AUTHOR_EMAIL='$(git config user.email || echo "${USER}@gmail.com")'
133+
export AUTHOR_WEBSITE='https://example.com/'
134+
export AUTHOR_GIT='http://github.com/$(git config user.name || echo "${USER}")'
135+
export LICENSE_DIR='$LICENSE_DIR'
136136
EOF
137137

138138
echo "$REPLY" >"$LICENSE_CONF"
139139

140140
read -d '' <<-EOF
141-
#!/usr/bin/env sh
142-
export AUTHOR_NAME='$(git config user.name || echo "${USER}")'
143-
export AUTHOR_EMAIL='$(git config user.email || echo "${USER}@gmail.com")'
144-
export AUTHOR_WEBSITE='https://example.com/'
145-
export AUTHOR_GIT='http://github.com/$(git config user.name || echo "${USER}")'
146-
export LANGUAGE_DIR='$LANGUAGE_DIR'
141+
#!/usr/bin/env sh
142+
export AUTHOR_NAME='$(git config user.name || echo "${USER}")'
143+
export AUTHOR_EMAIL='$(git config user.email || echo "${USER}@gmail.com")'
144+
export AUTHOR_WEBSITE='https://example.com/'
145+
export AUTHOR_GIT='http://github.com/$(git config user.name || echo "${USER}")'
146+
export LANGUAGE_DIR='$LANGUAGE_DIR'
147147
EOF
148148

149149
echo "$REPLY" >"$LANGUAGE_CONF"
@@ -197,8 +197,13 @@ initialize_repo() {
197197

198198
check_valid_license() {
199199
lic="$(echo "$1" | sed "$LICENSE_SED")"
200-
echo "$1" | grep -qi '^@' || (error "License '$lic' is not valid" && exit 9)
201-
[[ ! -f "$LICENSE_DIR"/"$lic" ]] && (error "License '$lic' does not exist" && exit 10)
200+
if [[ $1 != \@* ]]; then
201+
error "License '$lic' is not valid"
202+
exit 9
203+
elif ! [[ -f $LICENSE_DIR/$lic ]]; then
204+
error "License '$lic' does not exist"
205+
exit 10
206+
fi
202207

203208
return 0
204209
}
@@ -210,8 +215,13 @@ check_valid_license() {
210215

211216
check_valid_language() {
212217
lang="$(echo "$1" | sed "$LANGUAGE_SED")"
213-
echo "$1" | grep -qi '^@' || (error "Language '$lang' is not valid" && exit 9)
214-
[[ ! -f "$LANGUAGE_DIR"/"$lang" ]] && (error "Language '$lang' does not exist" && exit 10)
218+
if [[ $1 != \@* ]]; then
219+
error "License '$lang' is not valid"
220+
exit 9
221+
elif ! [[ -f $LANGUAGE_DIR/$lang ]]; then
222+
error "License '$lang' does not exist"
223+
exit 10
224+
fi
215225

216226
return 0
217227
}
@@ -310,67 +320,64 @@ get_license() {
310320
#==============================================================================
311321

312322
get_language() {
313-
printf 'Chose a name for the file (spaces will be removed) -- '
314-
read -r l_name
323+
read -p 'Chose a name for the file (spaces will be removed) -- '
315324

316-
[[ -z "$l_name" ]] && (
317-
error 'Cannot leave file name empty'
318-
exit 7
319-
)
325+
if [[ -z "$REPLY" ]]; then
326+
error 'Cannot leave file name empty'
327+
exit 7
328+
fi
320329

321-
l_name="$(echo "$l_name" | tr -d ' ' | head -c250)"
330+
l_name="$(echo "$REPLY" | tr -d ' ' | head -c250)"
322331

323-
depend 'cp'
324-
check_valid_language "$1"
332+
depend 'cp'
333+
check_valid_language "$1"
325334

326-
user_language="$(echo "$1" | sed "$LANGUAGE_SED")"
335+
user_language="$(echo "$1" | sed "$LANGUAGE_SED")"
327336

328-
if [[ ! -f "$LANGUAGE_DIR"/"$user_language" ]]; then
329-
error "No language by the name of '$user_language'"
330-
list_languages
331-
error 'Use one of the above'
337+
if [[ ! -f "$LANGUAGE_DIR"/"$user_language" ]]; then
338+
error "No language by the name of '$user_language'"
339+
list_languages
340+
error 'Use one of the above'
332341

333-
exit 5
334-
elif [[ -f "$l_name" ]]; then
335-
printf 'This file already exists, do you want to overwrite it? [y/N] '
336-
read -r yn
342+
exit 5
343+
elif [[ -f "$l_name" ]]; then
344+
read -p 'This file already exists, do you want to overwrite it? [y/N] '
337345

338-
[[ "$yn" != 'y' ]] && exit
339-
printf ' Last chance you can not go back from here? [y/N] '
340-
read -r lc
346+
[[ $REPLY == y ]] || exit
347+
read -p ' Last chance you can not go back from here? [y/N] '
341348

342-
[[ ! "$lc" = "y" ]] && exit
343-
fi
349+
[[ $REPLY == y ]] || exit
350+
fi
344351

345-
cp -rfL "$LANGUAGE_DIR"/"$user_language" "$l_name"
352+
cp -rfL "$LANGUAGE_DIR"/"$user_language" "$l_name"
346353

347-
sed -i "$l_name" \
348-
-e "s/{{PROJECT_NAME}}/$(sed_escape "$(basename "$l_name")")/g" \
349-
-e "s/{{AUTHOR_WEBSITE}}/$(sed_escape "$AUTHOR_WEBSITE")/g" \
350-
-e "s/{{CURRENT_DATE}}/$(sed_escape "$(date '+%a %d %B %Y, %I:%M:%S %P (%Z)')")/g" \
351-
-e "s/{{AUTHOR_EMAIL}}/$(sed_escape "$AUTHOR_EMAIL")/g" \
352-
-e "s/{{AUTHOR_NAME}}/$(sed_escape "$AUTHOR_NAME")/g" \
353-
-e "s/{{AUTHOR_GIT}}/$(sed_escape "$AUTHOR_GIT")/g"
354+
sed -i "$l_name" \
355+
-e "s/{{PROJECT_NAME}}/$(sed_escape "$(basename "$l_name")")/g" \
356+
-e "s/{{AUTHOR_WEBSITE}}/$(sed_escape "$AUTHOR_WEBSITE")/g" \
357+
-e "s/{{CURRENT_DATE}}/$(sed_escape "$(date '+%a %d %B %Y, %I:%M:%S %P (%Z)')")/g" \
358+
-e "s/{{AUTHOR_EMAIL}}/$(sed_escape "$AUTHOR_EMAIL")/g" \
359+
-e "s/{{AUTHOR_NAME}}/$(sed_escape "$AUTHOR_NAME")/g" \
360+
-e "s/{{AUTHOR_GIT}}/$(sed_escape "$AUTHOR_GIT")/g"
354361

355-
editor="${EDITOR:-}"
362+
editor="${EDITOR:-}"
356363

357-
if [[ -z "$editor" ]]; then
358-
printf 'Editor to open file in -- '
359-
read -r editor
360-
fi
364+
if [[ -z "$editor" ]]; then
365+
printf 'Editor to open file in -- '
366+
read -r editor
367+
fi
361368

362-
[[ -z "$editor" ]] && (
363-
error 'Cannot leave editor empty'
364-
exit 8
365-
)
369+
if [[ -z "$editor" ]]; then
370+
error 'Cannot leave editor empty'
371+
exit 8
372+
fi
366373

367-
depend "$(basename "$editor" | awk '{print $1}')"
374+
depend "$(basename "$editor")"
368375

369-
set -x
370-
$editor "$l_name"
371-
set +x
376+
set -x
377+
$editor "$l_name"
378+
set +x
372379

373-
info "Current language for $l_name is now set to $user_language"
380+
info "Current language for $l_name is now set to $user_language"
374381
}
375382

376383
#=== FUNCTION =================================================================
@@ -487,7 +494,7 @@ templating_help() {
487494

488495
list_types() {
489496
printf "language
490-
license"
497+
license"
491498

492499
}
493500

@@ -501,79 +508,75 @@ new_template() {
501508
FZF_DEFAULT_OPTS='' fzf --layout=reverse --height=20 --no-mouse -i || echo '')"
502509

503510
if [[ "$type" == "license" ]]; then
504-
printf 'License name/alias (spaces will be removed) -- '
505-
read -r ln
511+
read -p 'License name/alias (spaces will be removed) -- '
506512

507-
[[ -z "$ln" ]] && (
508-
error 'Cannot leave license name empty'
509-
exit 7
510-
)
513+
if [[ -z "$REPLY" ]]; then
514+
error 'Cannot leave language name empty'
515+
exit 7
516+
fi
511517

512-
ln="$LICENSE_DIR/$(echo "$ln" | tr -d ' ' | head -c250)"
518+
ln="$LICENSE_DIR/$(echo "$REPLY" | tr -d ' ' | head -c250)"
513519

514-
if [[ -f "$ln" ]]; then
515-
printf 'This license already exists, do you want to overwrite it? [y/N] '
516-
read -r yn
520+
if [[ -f "$ln" ]]; then
521+
read -p 'This license already exists, do you want to overwrite it? [y/N] '
517522

518-
[[ "$yn" != 'y' ]] && exit
519-
fi
523+
[[ $REPLY == y ]] || exit
524+
fi
520525

521-
editor="${EDITOR:-}"
526+
editor="${EDITOR:-}"
522527

523-
if [[ -z "$editor" ]]; then
524-
printf 'Editor to open file in -- '
525-
read -r editor
526-
fi
528+
if [[ -z "$editor" ]]; then
529+
printf 'Editor to open file in -- '
530+
read -r editor
531+
fi
527532

528-
[[ -z "$editor" ]] && (
529-
error 'Cannot leave editor empty'
530-
exit 8
531-
)
533+
if [[ -z "$editor" ]]; then
534+
error 'Cannot leave editor empty'
535+
exit 8
536+
fi
532537

533-
depend "$(basename "$editor" | awk '{print $1}')"
538+
depend "$(basename "$editor" | awk '{print $1}')"
534539

535-
set -x
536-
$editor "$ln"
537-
set +x
540+
set -x
541+
$editor "$ln"
542+
set +x
538543

539-
[[ -f "$ln" ]] && einfo "License '$(basename "$ln")' saved"
540-
elif [[ "$type" == "language" ]]; then
541-
printf 'Language name/alias (spaces will be removed) -- '
542-
read -r ln
544+
[[ -f "$ln" ]] && einfo "License '$(basename "$ln")' saved"
543545

544-
[[ -z "$ln" ]] && (
545-
error 'Cannot leave language name empty'
546-
exit 7
547-
)
546+
elif [[ "$type" == "language" ]]; then
547+
read -p 'Language name/alias (spaces will be removed) -- '
548548

549-
ln="$LANGUAGE_DIR/$(echo "$ln" | tr -d ' ' | head -c250)"
549+
if [[ -z "$REPLY" ]]; then
550+
error 'Cannot leave language name empty'
551+
exit 7
552+
fi
553+
ln="$LANGUAGE_DIR/$(echo "$REPLY" | tr -d ' ' | head -c250)"
550554

551-
if [[ -f "$ln" ]]; then
552-
printf 'This language already exists, do you want to overwrite it? [y/N] '
553-
read -r yn
555+
if [[ -f "$ln" ]]; then
556+
read -p 'This language already exists, do you want to overwrite it? [y/N] '
554557

555-
[[ "$yn" != 'y' ]] && exit
556-
fi
558+
[[ $REPLY == y ]] || exit
559+
fi
557560

558-
editor="${EDITOR:-}"
561+
editor="${EDITOR:-}"
559562

560-
if [[ -z "$editor" ]]; then
561-
printf 'Editor to open file in -- '
562-
read -r editor
563-
fi
563+
if [[ -z "$editor" ]]; then
564+
printf 'Editor to open file in -- '
565+
read -r editor
566+
fi
564567

565-
[[ -z "$editor" ]] && (
566-
error 'Cannot leave editor empty'
567-
exit 8
568-
)
568+
if [[ -z "$editor" ]]; then
569+
error 'Cannot leave editor empty'
570+
exit 8
571+
fi
569572

570-
depend "$(basename "$editor" | awk '{print $1}')"
573+
depend "$(basename "$editor" | awk '{print $1}')"
571574

572-
set -x
573-
$editor "$ln"
574-
set +x
575+
set -x
576+
$editor "$ln"
577+
set +x
575578

576-
[[ -f "$ln" ]] && einfo "Language '$(basename "$ln")' saved"
579+
[[ -f "$ln" ]] && einfo "Language '$(basename "$ln")' saved"
577580
fi
578581
}
579582

@@ -593,11 +596,13 @@ delete_license() {
593596
#==============================================================================
594597

595598
new_config() {
596-
einfo "This will overwite your config, are you sure you want do do that?"
597-
printf ' [y/N] '
598-
read -r yn
599+
read -p 'This will overwite your config, are you sure you want do do that? [y/N]'
600+
601+
[[ $REPLY == y ]] || exit
602+
603+
read -p 'This language already exists, do you want to overwrite it? [y/N] '
599604

600-
[[ "$yn" != 'y' ]] && exit
605+
[[ $REPLY == y ]] || exit
601606

602607
make_new_config
603608
info 'New config made and saved'

0 commit comments

Comments
 (0)