@mihairo/cmt 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/cmt +36 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Conventional Commits CLI — zero dependencies, one bash script.
4
4
 
5
- [![npm](https://img.shields.io/npm/v/cmt-cli?label=npm)](https://npmjs.com/package/cmt-cli)
5
+ [![npm](https://img.shields.io/npm/v/@mihairo/cmt?label=npm)](https://npmjs.com/package/@mihairo/cmt)
6
6
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-fe5196?logo=conventionalcommits)](https://conventionalcommits.org)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
8
8
 
@@ -13,7 +13,7 @@
13
13
  **npm (any project — no Node required at runtime)**
14
14
 
15
15
  ```bash
16
- npm install -g cmt-cli
16
+ npm install -g @mihairo/cmt
17
17
  ```
18
18
 
19
19
  **Homebrew**
package/cmt CHANGED
@@ -492,13 +492,42 @@ assemble_message() {
492
492
  COMMIT_MESSAGE="$msg"
493
493
  }
494
494
 
495
+ _print_commit_box() {
496
+ local msg="$1" _max=0 _line _W _content_w _bar _bottom _max_W
497
+
498
+ _max_W=$(( ${COLUMNS:-$(tput cols 2>/dev/null || echo 80)} - 2 ))
499
+ [[ $_max_W -lt 50 ]] && _max_W=50
500
+
501
+ while IFS= read -r _line; do
502
+ [[ ${#_line} -gt $_max ]] && _max=${#_line}
503
+ done <<< "$msg"
504
+
505
+ _W=$(( _max + 6 ))
506
+ [[ $_W -lt 50 ]] && _W=50
507
+ [[ $_W -gt $_max_W ]] && _W=$_max_W
508
+ _content_w=$(( _W - 6 ))
509
+
510
+ printf -v _bar '%*s' $(( _W - 19 )) ''; _bar=${_bar// /─}
511
+ printf "\n ${MUTED}╭─ commit message %s╮${RESET}\n" "$_bar" >/dev/tty
512
+ while IFS= read -r _line; do
513
+ printf " ${MUTED}│${RESET} ${BOLD}%-${_content_w}s${RESET} ${MUTED}│${RESET}\n" "$_line" >/dev/tty
514
+ done <<< "$(printf '%s\n' "$msg" | awk -v w="$_content_w" '{
515
+ if (length($0) <= w) { print; next }
516
+ line = ""
517
+ for (i = 1; i <= NF; i++) {
518
+ if (line == "") { line = $i }
519
+ else if (length(line) + 1 + length($i) <= w) { line = line " " $i }
520
+ else { print line; line = $i }
521
+ }
522
+ if (line != "") print line
523
+ }')"
524
+ printf -v _bottom '%*s' $(( _W - 2 )) ''; _bottom=${_bottom// /─}
525
+ printf " ${MUTED}╰%s╯${RESET}\n" "$_bottom" >/dev/tty
526
+ }
527
+
495
528
  # confirm and commit
496
529
  confirm_and_commit() {
497
- printf "\n ${MUTED}╭─ commit message ──────────────────────────────╮${RESET}\n" >/dev/tty
498
- while IFS= read -r _line; do
499
- printf " ${MUTED}│${RESET} ${BOLD}%s${RESET}\n" "$_line" >/dev/tty
500
- done <<< "$COMMIT_MESSAGE"
501
- printf " ${MUTED}╰───────────────────────────────────────────────╯${RESET}\n" >/dev/tty
530
+ _print_commit_box "$COMMIT_MESSAGE"
502
531
 
503
532
  printf "\n ${ACCENT_BOLD}commit?${RESET} ${MUTED}[Y/n/e]${RESET} ${ACCENT}›${RESET} " >/dev/tty
504
533
  read -r ans </dev/tty
@@ -558,11 +587,8 @@ cmd_commit() {
558
587
 
559
588
  if [[ $write_only -eq 1 ]]; then
560
589
  # show preview on /dev/tty (git won't capture it — only stdout goes to the msg file)
561
- printf "\n ${MUTED}╭─ commit message ──────────────────────────────╮${RESET}\n" >/dev/tty
562
- while IFS= read -r _line; do
563
- printf " ${MUTED}│${RESET} ${BOLD}%s${RESET}\n" "$_line" >/dev/tty
564
- done <<< "$COMMIT_MESSAGE"
565
- printf " ${MUTED}╰───────────────────────────────────────────────╯${RESET}\n\n" >/dev/tty
590
+ _print_commit_box "$COMMIT_MESSAGE"
591
+ printf "\n" >/dev/tty
566
592
  printf '%s' "$COMMIT_MESSAGE"
567
593
  return 0
568
594
  fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mihairo/cmt",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Zero-dependency conventional commits CLI — interactive picker, linter, and git hook installer. One bash script, works in any repo.",
5
5
  "keywords": [
6
6
  "conventional-commits",