Bug fix
This commit is contained in:
5
makefile
5
makefile
@@ -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
|
||||||
48
mapping.ts
48
mapping.ts
@@ -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",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user