1 Star 0 Fork 14

smalltsky/axe.store

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
_setup.gua 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
axe-store 提交于 2020-07-11 15:11 . 优化 exec 完成
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/smalltskyKepler/store.git
git@gitee.com:smalltskyKepler/store.git
smalltskyKepler
store
axe.store
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385