fix(go): modify init go
This commit is contained in:
@@ -101,7 +101,7 @@ bindkey "^b" backward-word
|
|||||||
bindkey "^f" forward-word
|
bindkey "^f" forward-word
|
||||||
|
|
||||||
# brew
|
# brew
|
||||||
export HOMEBREW_NO_AUTO_UPDATE=true # 禁止 brew 每次安装软件都 upate
|
export HOMEBREW_NO_AUTO_UPDATE=true # 禁止 brew 每次安装软件都 upate
|
||||||
|
|
||||||
# go
|
# go
|
||||||
export GOPROXY=goproxy.cn
|
export GOPROXY=goproxy.cn
|
||||||
@@ -110,7 +110,7 @@ export GOSUMDB="sum.golang.google.cn"
|
|||||||
[ -f ~/.zprofile ] && source ~/.zprofile
|
[ -f ~/.zprofile ] && source ~/.zprofile
|
||||||
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
|
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
|
||||||
|
|
||||||
# add z
|
# add z
|
||||||
eval "$(lua /usr/local/z.lua/z.lua --init zsh)"
|
eval "$(lua /usr/local/z.lua/z.lua --init zsh)"
|
||||||
|
|
||||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||||
|
|||||||
@@ -6,36 +6,39 @@ import argparse
|
|||||||
|
|
||||||
home_dir = os.getenv("HOME")
|
home_dir = os.getenv("HOME")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-i","--install", help="install tools",type=str)
|
parser.add_argument("-i", "--init", help="init tools", type=str)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
installer = Installer()
|
installer = Installer()
|
||||||
installer.install(args.install)
|
installer.install(args.init)
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
class Base(object):
|
||||||
def cmd_exist(self, name):
|
def cmd_exist(self, name):
|
||||||
from shutil import which
|
from shutil import which
|
||||||
return which(name) is not None
|
return which(name) is not None
|
||||||
|
|
||||||
def check_link(self, name:str,target:str):
|
def check_link(self, name: str, target: str):
|
||||||
if os.path.islink(name):
|
if os.path.islink(name):
|
||||||
t = os.readlink(name)
|
t = os.readlink(name)
|
||||||
if t == target:
|
if t == target:
|
||||||
return
|
return
|
||||||
os.system("mv %s %s.bak"%(name,name))
|
os.system("mv %s %s.bak" % (name, name))
|
||||||
os.system("ln -s %s %s"%(target,name))
|
os.system("ln -s %s %s" % (target, name))
|
||||||
|
|
||||||
|
|
||||||
class Installer(Base):
|
class Installer(Base):
|
||||||
def install(self, val:str):
|
def install(self, val: str):
|
||||||
if val== "":
|
if val == "":
|
||||||
print("install value is empty")
|
print("install value is empty")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
install_map = {
|
install_map = {
|
||||||
"neovim": self.install_neovim,
|
"neovim": self.install_neovim,
|
||||||
"z": self.install_z,
|
"z": self.install_z,
|
||||||
"git": self.install_git,
|
"git": self.install_git,
|
||||||
"packer": self.install_packer,
|
|
||||||
"go": self.install_go,
|
"go": self.install_go,
|
||||||
}
|
}
|
||||||
if val in install_map:
|
if val in install_map:
|
||||||
@@ -43,61 +46,54 @@ class Installer(Base):
|
|||||||
else:
|
else:
|
||||||
print("cmd not support, install: "+val)
|
print("cmd not support, install: "+val)
|
||||||
|
|
||||||
|
|
||||||
# install neovim
|
# install neovim
|
||||||
def install_neovim(self):
|
def install_neovim(self):
|
||||||
if not self.cmd_exist("nvim"):
|
if not self.cmd_exist("nvim"):
|
||||||
os.chdir("/usr/local")
|
os.chdir("/usr/local")
|
||||||
os.system("wget https://github.com/neovim/neovim/releases/download/v0.6.0/nvim-macos.tar.gz")
|
os.system(
|
||||||
|
"wget https://github.com/neovim/neovim/releases/download/v0.6.0/nvim-macos.tar.gz")
|
||||||
os.system("tar zxf nvim-macos.tar.gz")
|
os.system("tar zxf nvim-macos.tar.gz")
|
||||||
os.system("ln -s /usr/local/nvim-osx64 /usr/local/nvim")
|
os.system("ln -s /usr/local/nvim-osx64 /usr/local/nvim")
|
||||||
self.check_link(home_dir+"/.config/nvim",home_dir+"/.doftile/nvim")
|
self.check_link(home_dir+"/.config/nvim", home_dir+"/.doftile/nvim")
|
||||||
|
|
||||||
def install_z(self):
|
def install_z(self):
|
||||||
if not os.path.exists("/usr/local/z.lua"):
|
if not os.path.exists("/usr/local/z.lua"):
|
||||||
os.system("git clone --depth=1 https://github.com/skywind3000/z.lua.git /usr/local/z.lua")
|
run("git clone --depth=1 https://github.com/skywind3000/z.lua.git /usr/local/z.lua")
|
||||||
|
|
||||||
def install_git(self):
|
def install_git(self):
|
||||||
if not self.cmd_exist("git"):
|
if not self.cmd_exist("git"):
|
||||||
print("git is not exist")
|
print("git is not exist")
|
||||||
self.check_link(home_dir+"/.gitconfig", home_dir+"/.dotfile/git/.gitconfig")
|
self.check_link(home_dir+"/.gitconfig", home_dir +
|
||||||
|
"/.dotfile/git/.gitconfig")
|
||||||
|
|
||||||
def install_packer(self):
|
|
||||||
if not os.path.exists(home_dir+"/.local/share/nvim/site/pack/packer/start/packer.nvim"):
|
|
||||||
os.system("git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim")
|
|
||||||
else:
|
|
||||||
print("packer already installed")
|
|
||||||
def install_go(self):
|
def install_go(self):
|
||||||
version = urllib.request.urlopen("https://go.dev/VERSION?m=text").read()
|
|
||||||
if self.cmd_exist("go"):
|
|
||||||
run("go version")
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.chdir("/usr/local/")
|
os.chdir("/usr/local")
|
||||||
name = "%s.darwin-amd64.tar.gz"%(version.decode())
|
if os.path.exists("/usr/local/opt/go/libexec"):
|
||||||
u="https://dl.google.com/go/"+name
|
run("sudo mv go go_old")
|
||||||
run("sudo mv go go_old")
|
run("sudo ln -s /usr/local/opt/go/libexec /usr/local/go")
|
||||||
run("sudo rm "+name)
|
|
||||||
run("sudo wget "+u)
|
|
||||||
run("sudo tar zxf "+name)
|
|
||||||
run("go version")
|
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
run("go install golang.org/x/tools/gopls@latest")
|
run("go install golang.org/x/tools/gopls@latest")
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
class Base(object):
|
||||||
def cmd_exist(self, name):
|
def cmd_exist(self, name):
|
||||||
from shutil import which
|
from shutil import which
|
||||||
return which(name) is not None
|
return which(name) is not None
|
||||||
|
|
||||||
def check_link(self, name:str,target:str):
|
def check_link(self, name: str, target: str):
|
||||||
if os.path.islink(name):
|
if os.path.islink(name):
|
||||||
t = os.readlink(name)
|
t = os.readlink(name)
|
||||||
if t == target:
|
if t == target:
|
||||||
print("path is right: %s"%name)
|
print("path is right: %s" % name)
|
||||||
return
|
return
|
||||||
os.system("mv %s %s.bak"%(name,name))
|
os.system("mv %s %s.bak" % (name, name))
|
||||||
os.system("ln -s %s %s"%(target,name))
|
os.system("ln -s %s %s" % (target, name))
|
||||||
|
|
||||||
def run(cmd:str):
|
|
||||||
|
def run(cmd: str):
|
||||||
subprocess.run(cmd.split())
|
subprocess.run(cmd.split())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user