This commit is contained in:
2020-07-19 09:11:14 +09:00
parent 0e17fd4171
commit 1f0accc917
3 changed files with 54 additions and 35 deletions

View File

@@ -2,4 +2,7 @@ install:
deno run --unstable --allow-env --allow-run --allow-read --allow-write ./mapping.ts install deno run --unstable --allow-env --allow-run --allow-read --allow-write ./mapping.ts install
link: link:
deno run --unstable --allow-env --allow-run --allow-read --allow-write ./mapping.ts link deno run --unstable --allow-env --allow-run --allow-read --allow-write ./mapping.ts link
unlink:
deno run --unstable --allow-env --allow-run --allow-read --allow-write ./mapping.ts unlink

View File

@@ -2,7 +2,7 @@ import { dot, DotOption } from "./scripts/dot.ts";
const common: DotOption = { const common: DotOption = {
link: { link: {
gitconfig: ".gitconfig", ".gitconfig": "gitconfig",
}, },
}; };
@@ -24,23 +24,23 @@ const linux: DotOption = {
], ],
link: { link: {
...common.link, ...common.link,
"linux/alacritty": ".config/alacritty", ".config/alacritty": "linux/alacritty",
"linux/bin/ufetch": ".local/bin/ufetch", ".local/bin/ufetch": "linux/bin/ufetch",
"linux/bspwm": ".config/bspwm", ".config/bspwm": "linux/bspwm",
"linux/Code/User/settings.json": ".config/Code/User/settings.json", ".config/Code/User/settings.json": "linux/Code/User/settings.json",
"linux/dunst": ".config/dunst", ".config/dunst": "linux/dunst",
"linux/omz": ".config/omz", ".config/omz": "linux/omz",
"linux/picom": ".config/picom", ".config/picom": "linux/picom",
"linux/polybar": ".config/polybar", ".config/polybar": "linux/polybar",
"linux/rofi": ".config/rofi", ".config/rofi": "linux/rofi",
"linux/sxhkd": ".config/sxhkd", ".config/sxhkd": "linux/sxhkd",
"linux/fcitx5": ".config/fcitx5", ".config/fcitx5": "linux/fcitx5",
"linux/dconf": ".config/dconf", ".config/dconf": "linux/dconf",
"linux/bakamplayer.ini": ".config/bakamplayer.ini", ".config/bakamplayer.ini": "linux/bakamplayer.ini",
"linux/xinitrc": ".xinitrc", ".xinitrc": "linux/xinitrc",
"linux/pam_environment": ".pam_environment", ".pam_environment": "linux/pam_environment",
"linux/zshrc": ".zshrc", ".zshrc": "linux/zshrc",
"linux/Xmodmap": ".Xmodmap", ".Xmodmap": "linux/Xmodmap",
}, },
}; };
@@ -49,12 +49,12 @@ const linuxMacbook: DotOption = {
hostname: "MBP", hostname: "MBP",
link: { link: {
...linux.link, ...linux.link,
"linux-macbook/dconf": ".config/dconf", ".config/dconf": "linux-macbook/dconf",
"linux-macbook/polybar": ".config/polybar", ".config/polybar": "linux-macbook/polybar",
"linux-macbook/rofi": ".config/rofi", ".config/rofi": "linux-macbook/rofi",
"linux-macbook/sxhkd": ".config/sxhkd", ".config/sxhkd": "linux-macbook/sxhkd",
"linux-macbook/pam_environment": ".pam_environment", ".pam_environment": "linux-macbook/pam_environment",
"linux-macbook/Xresources": ".Xresources", ".Xresources": "linux-macbook/Xresources",
}, },
}; };

View File

@@ -30,20 +30,36 @@ export async function dot(args: string[], options: DotOption[]) {
} }
} }
} else if (flags._[0] === "link" && target.link) { } else if (flags._[0] === "link" && target.link) {
for (const from in target.link) { for (const value in target.link) {
const from = target.link[value];
const to = `${Deno.env.get("HOME")}/${value}`;
try { try {
const path = `${Deno.env.get("HOME")}/${target.link[from]}`; if (existsSync(to)) {
if (existsSync(path)) { if (Deno.readLinkSync(to) === Deno.realPathSync(from)) continue;
let i = 0; let i = 0;
let mvPath = `${path}.bak`; let mvPath = `${to}.bak`;
while (existsSync(mvPath)) mvPath = `${path}.${++i}.bak`; while (existsSync(mvPath)) mvPath = `${to}.${++i}.bak`;
console.log(`${path} does exist. move to ${mvPath}`); console.log(`${to} does exist. move to ${mvPath}`);
moveSync(path, mvPath); moveSync(to, mvPath);
} }
await ensureSymlink(Deno.realPathSync(from), path); await ensureSymlink(Deno.realPathSync(from), to);
console.log(`Link: ${path}`); console.log(`Link: ${to}`);
} catch (err) { } catch (err) {
throw Error(`${err.message}\nerror link: ${JSON.stringify(from)}`); throw Error(`${err.message}\nerror link: ${to}`);
}
}
} else if (flags._[0] === "unlink" && target.link) {
for (const value in target.link) {
const from = target.link[value];
const to = `${Deno.env.get("HOME")}/${value}`;
try {
if (existsSync(to)) {
if (Deno.readLinkSync(to) !== Deno.realPathSync(from)) continue;
Deno.removeSync(to);
console.log(`Unlink: ${to}`);
}
} catch (err) {
throw Error(`${err.message}\nerror link: ${to}`);
} }
} }
} }