tridactyl/src/config_rc.ts

30 lines
776 B
TypeScript
Raw Normal View History

import * as Controller from "./controller"
import * as Native from "./native_background"
import Logger from "./logging"
const logger = new Logger("rc")
export async function source(filename = "auto") {
let rctext = ""
if (filename == "auto") {
rctext = await Native.getrc()
} else {
rctext = (await Native.read(filename)).content
}
2018-05-11 21:33:10 +01:00
if (rctext === undefined) return false
runRc(rctext)
2018-05-11 21:33:10 +01:00
return true
}
export async function runRc(rc: string) {
for (let cmd of rcFileToExCmds(rc)) {
await Controller.acceptExCmd(cmd)
}
}
export function rcFileToExCmds(rcText: string): string[] {
const excmds = rcText.split("\n")
// Remove comment lines
return excmds.filter(x => x != "" && !x.trim().startsWith('"'))
}