init: initial commit
This commit is contained in:
+37
@@ -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
|
||||
@@ -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 <url>
|
||||
```
|
||||
|
||||
## 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.
|
||||
@@ -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=="],
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
const workDomains = [
|
||||
"example.com"
|
||||
];
|
||||
|
||||
|
||||
const directWorkURLs = [
|
||||
"https://example.com/folder/file.html"
|
||||
]
|
||||
|
||||
export { workDomains, directWorkURLs };
|
||||
@@ -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]);
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user