From 9aa3c7d07b3c83be31f9fa7728105853ffc3fc4f Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 8 Feb 2026 20:24:36 +0800 Subject: [PATCH] update git-check.ts --- single-scripts/git-check.ts | 38 ++++++++++++++++++++++++++++++------- single-scripts/pub | 6 ++++++ 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 single-scripts/pub diff --git a/single-scripts/git-check.ts b/single-scripts/git-check.ts index 72651e6..01d293c 100755 --- a/single-scripts/git-check.ts +++ b/single-scripts/git-check.ts @@ -7,10 +7,17 @@ import { ProcessBar, readFileToString, stringifyPretty, + term, uint8ArrayToHexString, writeStringToFile, } from "https://script.hatter.ink/@34/deno-commons-mod.ts"; -import {getGitLocalRev, getGitRemoteRev,} from "https://script.hatter.ink/@0/deno-git-mod.ts"; +import { + getGitLocalRev, + getGitRemoteRev, +} from "https://script.hatter.ink/@0/deno-git-mod.ts"; +import { parseArgs } from "jsr:@std/cli/parse-args"; + +const MILLIS_OF_HOUR = 60 * 60 * 1000; async function sha256OfString(input: string): Promise { const data = new TextEncoder().encode(input); @@ -30,6 +37,23 @@ interface GitCheckCache { } async function main() { + const flags = parseArgs(Deno.args, { + boolean: [ + "help", + ], + string: [ + "interval", + ], + }); + + if (flags.help) { + console.log(`Usage: +git-check.ts --help +git-check.ts [--interval NUMBER-OF-HOURS]`); + return; + } + const intervalHours = parseInt(flags.interval ?? "2", 10); + const pwd = await getPwd(); const pwdHash = await sha256OfString(pwd); const gitCheckCacheFile = `~/.cache/git-check-${ @@ -42,12 +66,12 @@ async function main() { : null; if (gitCheckCache) { const timeBefore = Date.now() - gitCheckCache.lastCheckTime; - if (timeBefore < 60 * 60 * 1000) { + if (timeBefore < MILLIS_OF_HOUR * intervalHours) { const lastCheckTime = new Date(gitCheckCache.lastCheckTime); const timeBeforeHuman = formatHumanTime(timeBefore); - log.info( - `Last check at ${lastCheckTime}, in ${timeBeforeHuman}, skip check git remote rev`, - ); + log.info(term.auto( + `Last check at [under]${lastCheckTime.toLocaleString()}[/], in [under]${timeBeforeHuman}[/], [green]skip check git remote rev[/]`, + )); return; } } @@ -76,5 +100,5 @@ async function main() { await main(); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260208T183447+08:00.MEYCIQCizSoZCohVIszX24vf -// kYa6qKDOpEBl0xwcMz8oY4U4wAIhAM0QzPVsFVZMO5379wA2nQdp0KrjDDzAr2zdd2kVMd7z +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260208T202409+08:00.MEUCIQDQct1xYu1frnSk3uzu +// RZ5WHoOdBCzaMDAe16JIbKZlGAIgZ3gBrD8FIH+H6efI8C7mkyn3RjoAqa6PAz72KcX/d80= diff --git a/single-scripts/pub b/single-scripts/pub new file mode 100644 index 0000000..bdc3e5f --- /dev/null +++ b/single-scripts/pub @@ -0,0 +1,6 @@ +Script started on Sun Feb 8 19:18:45 2026 +Command: --type bun ssh-bun.ts +script: --type: No such file or directory + +Command exit status: 1 +Script done on Sun Feb 8 19:18:45 2026