|
5 | 5 | # GitHub - https://github.com/The-Repo-Club/ |
6 | 6 | # Author - The-Repo-Club [[email protected]] |
7 | 7 | # Start On - Fri 18 February 2022, 07:26:28 pm (GMT) |
8 | | -# Modified On - Fri 18 February 2022, 07:26:46 pm (GMT) |
| 8 | +# Modified On - Sat 19 February 2022, 04:44:59 pm (GMT) |
9 | 9 | # ------------------------------------------------------------------------- |
10 | 10 | # |
11 | 11 | # |
@@ -389,48 +389,101 @@ templating_help() { |
389 | 389 | } | lless |
390 | 390 | } |
391 | 391 |
|
| 392 | +#=== FUNCTION ================================================================= |
| 393 | +# Name: list_types |
| 394 | +# Description: list the types to pass to the template creator |
| 395 | +#============================================================================== |
| 396 | + |
| 397 | +list_types() { |
| 398 | + printf "language |
| 399 | +license" |
| 400 | + |
| 401 | +} |
| 402 | + |
392 | 403 | #=== FUNCTION ================================================================= |
393 | 404 | # Name: new_template |
394 | 405 | # Description: create a new template for language or license |
395 | 406 | #============================================================================== |
396 | 407 |
|
397 | 408 | new_template() { |
398 | | - printf 'License name/alias (spaces will be removed) -- ' |
399 | | - read -r ln |
| 409 | + type="$(list_types | |
| 410 | + FZF_DEFAULT_OPTS='' fzf --layout=reverse --height=20 --no-mouse -i || echo '')" |
400 | 411 |
|
401 | | - [[ -z "$ln" ]] && ( |
402 | | - error 'Cannot leave license name empty' |
403 | | - exit 7 |
404 | | - ) |
| 412 | + if [[ "$type" == "license" ]]; then |
| 413 | + printf 'License name/alias (spaces will be removed) -- ' |
| 414 | + read -r ln |
405 | 415 |
|
406 | | - ln="$LICENSE_DIR/$(echo "$ln" | tr -d ' ' | head -c250)" |
| 416 | + [[ -z "$ln" ]] && ( |
| 417 | + error 'Cannot leave license name empty' |
| 418 | + exit 7 |
| 419 | + ) |
407 | 420 |
|
408 | | - if [[ -f "$ln" ]]; then |
409 | | - printf 'This license already exists, do you want to overwrite it? [y/n] ' |
410 | | - read -r yn |
| 421 | + ln="$LICENSE_DIR/$(echo "$ln" | tr -d ' ' | head -c250)" |
411 | 422 |
|
412 | | - [[ "$yn" != 'y' ]] && exit |
413 | | - fi |
| 423 | + if [[ -f "$ln" ]]; then |
| 424 | + printf 'This license already exists, do you want to overwrite it? [y/n] ' |
| 425 | + read -r yn |
414 | 426 |
|
415 | | - editor="${EDITOR:-}" |
| 427 | + [[ "$yn" != 'y' ]] && exit |
| 428 | + fi |
416 | 429 |
|
417 | | - if [[ -z "$editor" ]]; then |
418 | | - printf 'Editor to open file in -- ' |
419 | | - read -r editor |
420 | | - fi |
| 430 | + editor="${EDITOR:-}" |
421 | 431 |
|
422 | | - [[ -z "$editor" ]] && ( |
423 | | - error 'Cannot leave editor empty' |
424 | | - exit 8 |
425 | | - ) |
| 432 | + if [[ -z "$editor" ]]; then |
| 433 | + printf 'Editor to open file in -- ' |
| 434 | + read -r editor |
| 435 | + fi |
| 436 | + |
| 437 | + [[ -z "$editor" ]] && ( |
| 438 | + error 'Cannot leave editor empty' |
| 439 | + exit 8 |
| 440 | + ) |
426 | 441 |
|
427 | | - depend "$(basename "$editor" | awk '{print $1}')" |
| 442 | + depend "$(basename "$editor" | awk '{print $1}')" |
428 | 443 |
|
429 | | - set -x |
430 | | - $editor "$ln" |
431 | | - set +x |
| 444 | + set -x |
| 445 | + $editor "$ln" |
| 446 | + set +x |
432 | 447 |
|
433 | | - [[ -f "$ln" ]] && einfo "License '$(basename "$ln")' saved" |
| 448 | + [[ -f "$ln" ]] && einfo "License '$(basename "$ln")' saved" |
| 449 | + elif [[ "$type" == "language" ]]; then |
| 450 | + printf 'Language name/alias (spaces will be removed) -- ' |
| 451 | + read -r ln |
| 452 | + |
| 453 | + [[ -z "$ln" ]] && ( |
| 454 | + error 'Cannot leave language name empty' |
| 455 | + exit 7 |
| 456 | + ) |
| 457 | + |
| 458 | + ln="$LANGUAGE_DIR/$(echo "$ln" | tr -d ' ' | head -c250)" |
| 459 | + |
| 460 | + if [[ -f "$ln" ]]; then |
| 461 | + printf 'This language already exists, do you want to overwrite it? [y/n] ' |
| 462 | + read -r yn |
| 463 | + |
| 464 | + [[ "$yn" != 'y' ]] && exit |
| 465 | + fi |
| 466 | + |
| 467 | + editor="${EDITOR:-}" |
| 468 | + |
| 469 | + if [[ -z "$editor" ]]; then |
| 470 | + printf 'Editor to open file in -- ' |
| 471 | + read -r editor |
| 472 | + fi |
| 473 | + |
| 474 | + [[ -z "$editor" ]] && ( |
| 475 | + error 'Cannot leave editor empty' |
| 476 | + exit 8 |
| 477 | + ) |
| 478 | + |
| 479 | + depend "$(basename "$editor" | awk '{print $1}')" |
| 480 | + |
| 481 | + set -x |
| 482 | + $editor "$ln" |
| 483 | + set +x |
| 484 | + |
| 485 | + [[ -f "$ln" ]] && einfo "Language '$(basename "$ln")' saved" |
| 486 | + fi |
434 | 487 | } |
435 | 488 |
|
436 | 489 | #=== FUNCTION ================================================================= |
|
0 commit comments