forked from nshen/learn-neovim-lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.mjs
More file actions
executable file
·109 lines (86 loc) · 2.45 KB
/
Copy pathinstall.mjs
File metadata and controls
executable file
·109 lines (86 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env zx
$.verbose = false;
const logo = `
┌──────────────┐
│ 安装脚本 │
└──────────────┘
`;
function green(message) {
console.log(chalk.green(message));
}
function red(message) {
console.error(chalk.red(message));
}
function blue(message) {
console.log(chalk.blue(message));
}
function exit(errorMessage) {
red(errorMessage);
red("退出");
process.exit(1);
}
async function yesOrQuit(questionString, func) {
let res = "";
while (res === "") {
res = await question(questionString + " ([y] 继续 / [n] 退出): ");
}
res.toLowerCase().startsWith("y") ? func() : exit("选择 No");
}
blue(logo);
blue("开始环境检测...");
const checklist = ["git", "nvim", "rg", "wget", "curl"];
let program;
try {
blue("");
for (program of checklist) {
await $`which ${program}`;
green(`-> ${program} 已安装`);
}
} catch (error) {
exit(`${program} 没有找到,请安装后再尝试`);
}
// TODO: check os
const home = os.homedir();
await cd(home);
// backup nvim folder
const nvimDir = ".config/nvim";
if (await fs.pathExists(nvimDir)) {
green(``);
await yesOrQuit(`${nvimDir} 已存在,自动备份后继续?`, async () => {
const filename = `${nvimDir}.${new Date().toISOString()}.bak`;
green(``);
green(`备份为 ${filename}`);
await $`mv .config/nvim ${filename}`;
});
}
// backup old plugins
const pluginsDir = ".local/share/nvim/site";
if (await fs.pathExists(pluginsDir)) {
green(``);
await yesOrQuit(
`插件目录 ${pluginsDir} 已存在,自动备份后继续?`,
async () => {
const filename = `${pluginsDir}.${new Date().toISOString()}.bak`;
green(``);
green(`备份为 ${filename}`);
await $`mv .local/share/nvim/site ${filename}`;
}
);
}
$.verbose = true;
blue("");
blue("开始下载全新配置,请稍后...");
// red(await $`pwd`);
await $`git clone --branch tyx https://github.com/Realtyxxx/learn-neovim-lua ${nvimDir}`;
blue("");
green("下载成功");
blue("");
blue("开始下载插件管理packer.nvim...");
await $`git clone --depth 1 https://github.com/wbthomason/packer.nvim .local/share/nvim/site/pack/packer/start/packer.nvim`;
green("");
green("下载成功");
const notice = `
安装完成,运行以下命令开启 Neovim 并安装插件(需要科学网络环境)
nvim +PackerSync
如遇失败可运行 :PackerSync 重新尝试`;
green(notice);