@@ -75,7 +75,7 @@ usage() {
7575 echo " \$ AUTHOR_WEBSITE -- '$AUTHOR_WEBSITE '"
7676 echo " \$ AUTHOR_GIT -- '$AUTHOR_GIT '"
7777 echo " \$ LICENSE_DIR -- '$LICENSE_DIR '"
78- echo " \$ LANGUAGE_DIR -- '$LANGUAGE_DIR '"
78+ echo " \$ LANGUAGE_DIR -- '$LANGUAGE_DIR '"
7979 echo ' '
8080 echo " [ENV=VAL ...] $( basename " $0 " ) <flag>"
8181 echo ' '
@@ -211,13 +211,13 @@ get_license() {
211211 if [[ ! -f " $LICENSE_DIR " /" $user_license " ]]; then
212212 error " No license by the name of '$1 '"
213213 list_licenses
214- error ' Use of of the above'
214+ error ' Use one of the above'
215215
216216 exit 5
217217 elif [[ -f ./LICENSE ]] || [[ -f ./UNLICENSE ]]; then
218218 info " Found license: $( show_license) "
219219
220- printf ' Switch licenses? [y/n ] '
220+ printf ' Switch licenses? [y/N ] '
221221 read -r yn
222222
223223 [[ ! " $yn " = " y" ]] && exit
@@ -226,7 +226,11 @@ get_license() {
226226 l_name=' LICENSE'
227227 [[ " $( head -n1 " $LICENSE_DIR " /" $user_license " ) " = ' UNLICENSE' ]] && l_name=' UNLICENSE'
228228
229- cp -fiL " $LICENSE_DIR " /" $user_license " " $l_name "
229+ printf ' Last chance you can not go back from here? [y/N] '
230+ read -r lc
231+
232+ [[ ! " $lc " = " y" ]] && exit
233+ cp -rfL " $LICENSE_DIR " /" $user_license " " $l_name "
230234
231235 sed -i " $l_name " \
232236 -e " s/{{PROJECT_NAME}}/$( sed_escape " $( basename " $PWD " ) " ) /g" \
@@ -247,29 +251,39 @@ get_license() {
247251# ==============================================================================
248252
249253get_language () {
254+ printf ' Chose a name for the file (spaces will be removed) -- '
255+ read -r l_name
256+
257+ [[ -z " $l_name " ]] && (
258+ error ' Cannot leave file name empty'
259+ exit 7
260+ )
261+
262+ l_name=" $( echo " $l_name " | tr -d ' ' | head -c250) "
263+
250264 depend ' cp'
251265 check_valid_language " $1 "
252266
253267 user_language=" $( echo " $1 " | sed " $LANGUAGE_SED " ) "
254268
255269 if [[ ! -f " $LANGUAGE_DIR " /" $user_language " ]]; then
256- error " No language by the name of '$1 '"
270+ error " No language by the name of '$user_language '"
257271 list_languages
258- error ' Use of of the above'
272+ error ' Use one of the above'
259273
260274 exit 5
261- elif [[ -f ./main ]]; then
262- info " Found main file"
263-
264- printf ' Override main file? [y/n] '
275+ elif [[ -f " $l_name " ]]; then
276+ printf ' This file already exists, do you want to overwrite it? [y/N] '
265277 read -r yn
266278
267- [[ ! " $yn " = " y " ]] && exit
279+ [[ " $yn " != ' y ' ]] && exit
268280 fi
281+ printf ' Last chance you can not go back from here? [y/N] '
282+ read -r lc
269283
270- l_name= ' main '
284+ [[ ! " $lc " = " y " ]] && exit
271285
272- cp -fiL " $LANGUAGE_DIR " /" $user_language " " $l_name "
286+ cp -rfL " $LANGUAGE_DIR " /" $user_language " " $l_name "
273287
274288 sed -i " $l_name " \
275289 -e " s/{{PROJECT_NAME}}/$( sed_escape " $( basename " $PWD " ) " ) /g" \
@@ -279,7 +293,25 @@ get_language() {
279293 -e " s/{{AUTHOR_NAME}}/$( sed_escape " $AUTHOR_NAME " ) /g" \
280294 -e " s/{{AUTHOR_GIT}}/$( sed_escape " $AUTHOR_GIT " ) /g"
281295
282- info " Current language now is set to $user_language "
296+ editor=" ${EDITOR:- } "
297+
298+ if [[ -z " $editor " ]]; then
299+ printf ' Editor to open file in -- '
300+ read -r editor
301+ fi
302+
303+ [[ -z " $editor " ]] && (
304+ error ' Cannot leave editor empty'
305+ exit 8
306+ )
307+
308+ depend " $( basename " $editor " | awk ' {print $1}' ) "
309+
310+ set -x
311+ $editor " $l_name "
312+ set +x
313+
314+ info " Current language for $l_name is now set to $user_language "
283315}
284316
285317# === FUNCTION =================================================================
@@ -421,7 +453,7 @@ new_template() {
421453 ln=" $LICENSE_DIR /$( echo " $ln " | tr -d ' ' | head -c250) "
422454
423455 if [[ -f " $ln " ]]; then
424- printf ' This license already exists, do you want to overwrite it? [y/n ] '
456+ printf ' This license already exists, do you want to overwrite it? [y/N ] '
425457 read -r yn
426458
427459 [[ " $yn " != ' y' ]] && exit
@@ -458,7 +490,7 @@ new_template() {
458490 ln=" $LANGUAGE_DIR /$( echo " $ln " | tr -d ' ' | head -c250) "
459491
460492 if [[ -f " $ln " ]]; then
461- printf ' This language already exists, do you want to overwrite it? [y/n ] '
493+ printf ' This language already exists, do you want to overwrite it? [y/N ] '
462494 read -r yn
463495
464496 [[ " $yn " != ' y' ]] && exit
@@ -503,7 +535,7 @@ delete_license() {
503535
504536new_config () {
505537 einfo " This will overwite your config, are you sure you want do do that?"
506- printf ' [y/n ] '
538+ printf ' [y/N ] '
507539 read -r yn
508540
509541 [[ " $yn " != ' y' ]] && exit
@@ -535,6 +567,12 @@ main() {
535567 mkdir -p " $LICENSE_DIR "
536568 fi
537569
570+ if [[ ! -d " $LANGUAGE_DIR " ]]; then
571+ # shellcheck disable=2088
572+ warn " '$LANGUAGE_DIR ' does not exist. Creating it."
573+ mkdir -p " $LANGUAGE_DIR "
574+ fi
575+
538576 [[ -z " $1 " ]] && (
539577 usage
540578 exit 1
@@ -575,7 +613,7 @@ main() {
575613 -new-config | -C) new_config ;;
576614 -check-conflict | -k) check_license_conflict ;;
577615
578- @* ) check_valid_license " $1 " && get_license " $1 " ;;
616+ @* ) check_valid_license " $1 " && check_valid_language " $1 " && get_license " $1 " ;;
579617 * ) error " Flag $1 is not known." && usage && exit 2 ;;
580618 esac
581619}
0 commit comments