Add macbook rules

This commit is contained in:
2020-07-19 08:11:39 +09:00
parent 05c150d45f
commit 8286a58cd6
12 changed files with 573 additions and 28 deletions

View File

@@ -9,7 +9,7 @@ import {
export interface DotOption {
hostname?: string | string[];
install?: string[];
link?: [string, string][];
link?: Record<string, string>;
}
export async function dot(args: string[], options: DotOption[]) {
@@ -30,17 +30,20 @@ export async function dot(args: string[], options: DotOption[]) {
}
}
} else if (flags._[0] === "link" && target.link) {
for (const link of target.link) {
for (const from in target.link) {
try {
const path = `${Deno.env.get("HOME")}/${link[1]}`;
const path = `${Deno.env.get("HOME")}/${target.link[from]}`;
if (existsSync(path)) {
console.log(`${path} does exist. move to ${path}.bak`);
moveSync(path, `${path}.bak`);
let i = 0;
let mvPath = `${path}.bak`;
while (existsSync(mvPath)) mvPath = `${path}.${++i}.bak`;
console.log(`${path} does exist. move to ${mvPath}`);
moveSync(path, mvPath);
}
await ensureSymlink(Deno.realPathSync(link[0]), path);
await ensureSymlink(Deno.realPathSync(from), path);
console.log(`Link: ${path}`);
} catch (err) {
throw Error(`${err.message}\nerror link: ${JSON.stringify(link)}`);
throw Error(`${err.message}\nerror link: ${JSON.stringify(from)}`);
}
}
}