代码拉取完成,页面将自动刷新
const importUtil = import("util")
const fileExist = function(file_path) {
var exist = importUtil.guaFileExist(file_path)
return exist
}
const linesFromFile = function(path) {
var content = importUtil.readFile(path)
var lines = content.split('\n')
return lines
}
const writeLinesToFile = function(path, lines) {
var cleanedContent = lines.join('\n')
cleanedContent.writeToFile(path)
}
const addToPaths = function() {
var path = '/etc/paths'
var lines = linesFromFile(path)
var cleanedLines = []
var i = 0
while (i < lines.length()) {
i += 1
var index = i - 1
var line = lines[index]
if (line.startswith('/usr/local/axe')) {
continue
} else if (line.strip() == '') {
continue
} else {
cleanedLines.add(line)
}
}
var axeBin = '/usr/local/axe/bin\n'
cleanedLines.add(axeBin)
writeLinesToFile(path, cleanedLines)
}
const shellrcPath = function(shell, user) {
var rcFile = ''
if (shell == 'zsh') {
rcFile = '.zshrc'
} else if (shell == 'bash') {
rcFile = '.bashrc'
} else {
return null
}
var p = '/Users/{}/{}'.format(user, rcFile)
return p
}
const hasAddShellFunction = function(path) {
const e = importUtil.guaFileExist(path)
if (not e) {
return false
} else {
var content = stringFromFile(path)
return content.has('store.axe')
}
}
const addShellFunction = function(path, user) {
// 未知 shell
if (path == null) {
return
}
const e = importUtil.guaFileExist(path)
// 文件不存在, 则创建
if (not e) {
''.writeToFile(path)
const c = 'chown {} {}'.format(user, path)
importUtil.callWithoutOutput(c)
}
var content = stringFromFile(path)
// 已经写入过
if (content.has('store.axe')) {
return
} else {
const lines = linesFromFile(path)
const func = `
# axe init
store.axe()
{
/usr/local/axe/meta/gualang /usr/local/axe/meta/bin/store.gua "$@"
hash -r
}
# axe init
`
const addLines = func.split('\n')
lines.extend(addLines)
writeLinesToFile(path, lines)
}
}
const addToShells = function(user) {
var pathZsh = shellrcPath('zsh', user)
var pathBash = shellrcPath('bash', user)
var e1 = hasAddShellFunction(pathZsh)
var e2 = hasAddShellFunction(pathBash)
if (e1 and e2) {
return false
}
var shells = [
pathZsh,
pathBash,
]
for (var i = 0; i < shells.length(); i += 1) {
var path = shells[i]
addShellFunction(path, user)
}
return true
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。