From 49b466d098a6760119d1eca4685e8baa97ec6c2b Mon Sep 17 00:00:00 2001 From: Suraj B M Date: Sun, 26 Jul 2026 10:35:21 +0530 Subject: [PATCH] init: inital commit --- .gitignore | 37 +++++++++++++++++++++++++++++++++++++ README.md | 25 +++++++++++++++++++++++++ bun.lock | 26 ++++++++++++++++++++++++++ data.example.ts | 13 +++++++++++++ index.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 15 +++++++++++++++ tsconfig.json | 30 ++++++++++++++++++++++++++++++ 7 files changed, 191 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 bun.lock create mode 100644 data.example.ts create mode 100755 index.ts create mode 100644 package.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49f7c21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# dependencies (bun install) +node_modules + +# output +out +dist +*.tgz + +# code coverage +coverage +*.lcov + +# logs +logs +_.log +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# caches +.eslintcache +.cache +*.tsbuildinfo + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store + +# data.ts +data.ts \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5de7a5a --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# browser-dispatcher + +A simple script to open a work or personal browser based on the URL. + +## Usage + +```bash +bun run index.ts +``` + +## Configuration + +- `WORK_BROWSER`: The browser to use for work URLs. +- `PERSONAL_BROWSER`: The browser to use for personal URLs. + +## Data + +The data is stored in the `data.ts` file. + +- `workDomains`: An array of domains that are considered work URLs. +- `directWorkURLs`: An array of URLs that are considered work URLs. + +## How it works + +The script checks the URL and opens the appropriate browser based on the URL. \ No newline at end of file diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..54e234e --- /dev/null +++ b/bun.lock @@ -0,0 +1,26 @@ +{ + "lockfileVersion": 1, + "configVersion": 1, + "workspaces": { + "": { + "name": "browser-dispatcher", + "devDependencies": { + "@types/bun": "latest", + }, + "peerDependencies": { + "typescript": "^5", + }, + }, + }, + "packages": { + "@types/bun": ["@types/bun@1.3.14", "", { "dependencies": { "bun-types": "1.3.14" } }, "sha512-h1hFqFVcvAvD9j9K7ZW7vd82aSA+rTdznZa+5bwvCwqSB1jmmfLcbIWhOLx1/+boy/xmjgCs/OMUL8hRJSmnPw=="], + + "@types/node": ["@types/node@26.0.0", "", { "dependencies": { "undici-types": "~8.3.0" } }, "sha512-vf2YFi1iY9lHGwNJMs01biZFbKJkrZR1T6/MlzjhJLPdntOHLhTrDSnSVcdtvjihi4VQNlrFRIxLsDBlQpAipA=="], + + "bun-types": ["bun-types@1.3.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-4N0ig0fEomHt5R0KCFWjovxow98rIoRwKolrYdCcknNwMekCXRnWEUvgu5soYV8QXtVsrUD8B95MBOZGPvr6KQ=="], + + "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], + + "undici-types": ["undici-types@8.3.0", "", {}, "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ=="], + } +} diff --git a/data.example.ts b/data.example.ts new file mode 100644 index 0000000..418247b --- /dev/null +++ b/data.example.ts @@ -0,0 +1,13 @@ +const workDomains = [ + "gitlab.com", + "live.omnenest.com", + "twospoonai.slack.com" + ]; + + + const directWorkURLs = [ + // timesheet + "https://docs.google.com/spreadsheets/d/1nTn5Ee7IZrH-a-UJ2tfU49mgIll1znVjv9ZvQltGTVs/edit" + ] + +export { workDomains, directWorkURLs }; \ No newline at end of file diff --git a/index.ts b/index.ts new file mode 100755 index 0000000..28d7264 --- /dev/null +++ b/index.ts @@ -0,0 +1,45 @@ +#!/home/silicoflare/.bun/bin/bun + +import { spawn } from "bun"; +import { workDomains, directWorkURLs } from "./data"; + +const url = process.argv[2] ?? ""; + +const WORK_BROWSER = "firefox"; +const PERSONAL_BROWSER = "/home/silicoflare/Programs/waterfox/waterfox"; + +if (!workDomains || !directWorkURLs) { + console.error("Data is not loaded"); + process.exit(1); +} + +function getBrowser(url: string) { + const parsed = new URL(url); + + // query param based + const queryParams = parsed.searchParams; + if (queryParams.has("work")) { + return WORK_BROWSER; + } + + // domain based + const domain = parsed.hostname; + if (workDomains.some(workDomain => domain.includes(workDomain))) { + return WORK_BROWSER; + } + + // direct URL based + if (directWorkURLs.some(directWorkURL => url.includes(directWorkURL))) { + return WORK_BROWSER; + } + + return PERSONAL_BROWSER; +} + +if (!url) { + // open personal browser if no URL is provided + spawn([PERSONAL_BROWSER]); +} + +const browser = getBrowser(url); +spawn([browser, url]); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..5aa109b --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "browser-dispatcher", + "module": "index.ts", + "type": "module", + "private": true, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5" + }, + "scripts": { + "build": "bun build --compile --minify --outfile /home/silicoflare/bin/dispatch index.ts" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b2e7497 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + // Environment setup & latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "Preserve", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + "types": ["bun"], + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +}