Monty Anderson 1 year ago
commit
230adfe5b4
6 changed files with 108 additions and 0 deletions
  1. 15 0
      .vscode/deno.json
  2. 7 0
      .vscode/settings.json
  3. 8 0
      commit.sh
  4. 14 0
      deno.json
  5. 31 0
      readme.md
  6. 33 0
      summerize.ts

+ 15 - 0
.vscode/deno.json

@@ -0,0 +1,15 @@
+{
+	"fmt": {
+		"options": {
+			"useTabs": true,
+			"lineWidth": 80,
+			"indentWidth": 4,
+			"singleQuote": false,
+			"proseWrap": "preserve"
+		}
+	},
+	"importMap": "import_map.json",
+	"compilerOptions": {
+		"noUncheckedIndexedAccess": true
+	}
+}

+ 7 - 0
.vscode/settings.json

@@ -0,0 +1,7 @@
+{
+	"deno.enable": true,
+	"deno.lint": true,
+	"deno.config": "deno.json",
+	"editor.defaultFormatter": "denoland.vscode-deno",
+	"deno.importMap": "./import_map.json"
+}

+ 8 - 0
commit.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+git add .
+
+DIR="$( dirname "$0" )"
+FILES="$( git --no-pager diff --name-only HEAD )"
+CTX="$(cd "$DIR"; echo "$FILES" | deno run summerize.ts)"
+
+git commit -m "\`$CTX\`: $1";

+ 14 - 0
deno.json

@@ -0,0 +1,14 @@
+{
+	"fmt": {
+		"options": {
+			"useTabs": true,
+			"lineWidth": 80,
+			"indentWidth": 4,
+			"singleQuote": false,
+			"proseWrap": "preserve"
+		}
+	},
+	"compilerOptions": {
+		"noUncheckedIndexedAccess": true
+	}
+}

+ 31 - 0
readme.md

@@ -0,0 +1,31 @@
+# abstract
+
+Create commit messages with directory context.
+
+> a "form components"
+
+```
+[master cd19de8] `ui/components/*`: form components
+ 3 files changed, 0 insertions(+), 0 deletions(-)
+ create mode 100644 ui/components/Button.vue
+ create mode 100644 ui/components/Input.vue
+ create mode 100644 ui/components/Select.vue
+```
+
+## install
+
+```
+git clone https://github.com/montyanderson/abstract ~/.abstract
+```
+
+If you're using Mac OS / ZSH:
+
+```
+echo "alias \"a=$HOME/.abstract/commit.sh\"" >> ~/.zshrc
+```
+
+If you're using Linux / Bash:
+
+```
+echo "alias \"a=$HOME/.abstract/commit.sh\"" >> ~/.bashrc
+```

+ 33 - 0
summerize.ts

@@ -0,0 +1,33 @@
+import {
+	readAll,
+	writeAll,
+} from "https://deno.land/std@0.181.0/streams/mod.ts";
+
+const input = new TextDecoder().decode(await readAll(Deno.stdin));
+
+const files = input
+	.split("\n")
+	.filter((line) => line.length);
+
+const paths = files.map((file) => file.split("/"));
+
+let result = "";
+
+for (let i = 0;; i++) {
+	const chunks = paths.map((path) => path[i]);
+
+	if (chunks.every((chunk) => chunk === chunks[0])) {
+		if (chunks[0] === undefined) {
+			break;
+		}
+
+		result += chunks[0] + "/";
+	} else {
+		result += "*/";
+		break;
+	}
+}
+
+result = result.slice(0, -1);
+
+await writeAll(Deno.stdout, new TextEncoder().encode(result));