0 Star 1 Fork 0

蒋佳李 / vault

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
zsh.go 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
蒋佳李 提交于 2021-03-25 16:28 . 更新
package install
import "fmt"
// (un)install in zsh
// basically adds/remove from .zshrc:
//
// autoload -U +X bashcompinit && bashcompinit"
// complete -C </path/to/completion/command> <command>
type zsh struct {
rc string
}
func (z zsh) IsInstalled(cmd, bin string) bool {
completeCmd := z.cmd(cmd, bin)
return lineInFile(z.rc, completeCmd)
}
func (z zsh) Install(cmd, bin string) error {
if z.IsInstalled(cmd, bin) {
return fmt.Errorf("already installed in %s", z.rc)
}
completeCmd := z.cmd(cmd, bin)
bashCompInit := "autoload -U +X bashcompinit && bashcompinit"
if !lineInFile(z.rc, bashCompInit) {
completeCmd = bashCompInit + "\n" + completeCmd
}
return appendToFile(z.rc, completeCmd)
}
func (z zsh) Uninstall(cmd, bin string) error {
if !z.IsInstalled(cmd, bin) {
return fmt.Errorf("does not installed in %s", z.rc)
}
completeCmd := z.cmd(cmd, bin)
return removeFromFile(z.rc, completeCmd)
}
func (zsh) cmd(cmd, bin string) string {
return fmt.Sprintf("complete -o nospace -C %s %s", bin, cmd)
}
Go
1
https://gitee.com/jiangjiali/vault.git
git@gitee.com:jiangjiali/vault.git
jiangjiali
vault
vault
v1.1.11

搜索帮助