~glacambre/firenvim

ref: 076c1a4f04db2173afb395d0af8c63a5bbcab6a8 firenvim/tests/_vimrc.ts -rw-r--r-- 1.4 KiB
076c1a4f — Brian Ryall fixes installing fire nvim on brave 11 months ago
                                                                                
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
const fs = require("fs");
const os = require("os");
const path = require("path");
const process = require("process");
const spawn = require("child_process").spawn;

let init_vim: string;

export function setupVimrc() {
        const base_dir = path.join(os.tmpdir(), "firenvim_test_run", `${Math.round(Math.random() * 100000)}`);
        process.env.XDG_CONFIG_HOME = path.join(base_dir, "config");
        process.env.XDG_DATA_HOME = path.join(base_dir, "data");
        const nvim_conf_dir = path.join(process.env.XDG_CONFIG_HOME, "nvim");
        const nvim_data_dir = path.join(process.env.XDG_DATA_HOME, "nvim");
        try {
                fs.mkdirSync(nvim_conf_dir, { recursive: true });
                fs.mkdirSync(nvim_conf_dir, { recursive: true });
        } catch (e) {
                console.error("Failed to create config/data dirs");
        }
        init_vim = path.join(nvim_conf_dir, "init.vim");
        return resetVimrc();
};

export function resetVimrc() {
        return writeVimrc(`set rtp+=${process.cwd()}\n`);
}

export function readVimrc() {
        if (init_vim === undefined) {
                throw new Error("readVimrc called without setupVimrc!");
        }
        return fs.readFileSync(init_vim).toString();
};

export function writeVimrc(content: string) {
        if (init_vim === undefined) {
                throw new Error("writeVimrc called without setupVimrc!");
        }
        return fs.writeFileSync(init_vim, content);
};