feat: update init nvim
This commit is contained in:
@@ -117,5 +117,10 @@ export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
export PATH="/usr/local/sbin:$PATH"
|
||||
# add nvim
|
||||
export PATH=$PATH:/usr/local/nvim/bin:/usr/local/osx-64/nvim/bin
|
||||
|
||||
# for terminal notify
|
||||
# https://github.com/julienXX/terminal-notifier
|
||||
alias alert='terminal-notifier -title "Terminal" -message "Done with task! Exit status: $?"' -activate com.apple.Terminal
|
||||
|
||||
# git
|
||||
alias gitb="git branch --show-current | tr -d '\n' | pbcopy"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
import urllib.request
|
||||
import os
|
||||
import argparse
|
||||
|
||||
home_dir = os.getenv("HOME")
|
||||
dotfile_dir = home_dir+"/.dotfile"
|
||||
|
||||
|
||||
def main():
|
||||
@@ -12,79 +12,7 @@ def main():
|
||||
parser.add_argument("-i", "--init", help="init tools", type=str)
|
||||
args = parser.parse_args()
|
||||
installer = Installer()
|
||||
installer.install(args.init)
|
||||
|
||||
|
||||
class Base(object):
|
||||
def cmd_exist(self, name):
|
||||
from shutil import which
|
||||
return which(name) is not None
|
||||
|
||||
def check_link(self, name: str, target: str):
|
||||
if os.path.islink(name):
|
||||
t = os.readlink(name)
|
||||
if t == target:
|
||||
return
|
||||
os.system("mv %s %s.bak" % (name, name))
|
||||
os.system("ln -s %s %s" % (target, name))
|
||||
|
||||
|
||||
class Installer(Base):
|
||||
def install(self, val: str):
|
||||
if val == "":
|
||||
print("install value is empty")
|
||||
exit()
|
||||
|
||||
install_map = {
|
||||
"brew": self.install_brew,
|
||||
"neovim": self.install_neovim,
|
||||
"z": self.install_z,
|
||||
"git": self.install_git,
|
||||
"go": self.install_go,
|
||||
"tmux": self.init_tmux,
|
||||
}
|
||||
if val in install_map:
|
||||
install_map.get(val)()
|
||||
else:
|
||||
print("cmd not support, install: "+val)
|
||||
|
||||
# install neovim
|
||||
def install_neovim(self):
|
||||
if not self.cmd_exist("nvim"):
|
||||
os.chdir("/usr/local")
|
||||
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("ln -s /usr/local/nvim-osx64 /usr/local/nvim")
|
||||
self.check_link(home_dir+"/.config/nvim", home_dir+"/.doftile/nvim")
|
||||
|
||||
def install_z(self):
|
||||
if not os.path.exists("/usr/local/z.lua"):
|
||||
run("git clone --depth=1 https://github.com/skywind3000/z.lua.git /usr/local/z.lua")
|
||||
|
||||
def install_git(self):
|
||||
if not self.cmd_exist("git"):
|
||||
print("git is not exist")
|
||||
self.check_link(home_dir+"/.gitconfig", home_dir +
|
||||
"/.dotfile/git/.gitconfig")
|
||||
|
||||
def install_go(self):
|
||||
cwd = os.getcwd()
|
||||
os.chdir("/usr/local")
|
||||
if os.path.exists("/usr/local/opt/go/libexec"):
|
||||
run("sudo mv go go_old")
|
||||
run("sudo ln -s /usr/local/opt/go/libexec /usr/local/go")
|
||||
os.chdir(cwd)
|
||||
run("go install golang.org/x/tools/gopls@latest")
|
||||
|
||||
def install_brew(self):
|
||||
run("/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"")
|
||||
|
||||
def init_tmux(self):
|
||||
self.check_link(home_dir+"/.tmux.conf",
|
||||
home_dir+"/.dotfile/.tmux.conf")
|
||||
if not os.path.exists(home_dir+"/.tmux/plugins/tmux-resurrect"):
|
||||
run("git clone --depth=1 https://github.com/tmux-plugins/tmux-resurrect %s/.tmux/plugins/tmux-resurrect" % (home_dir))
|
||||
installer.doInit(args.init)
|
||||
|
||||
|
||||
class Base(object):
|
||||
@@ -98,8 +26,69 @@ class Base(object):
|
||||
if t == target:
|
||||
print("path is right: %s" % name)
|
||||
return
|
||||
os.system("mv %s %s.bak" % (name, name))
|
||||
os.system("ln -s %s %s" % (target, name))
|
||||
if os.path.exists(name):
|
||||
run("mv %s %s.bak" % (name, name))
|
||||
run("ln -s %s %s" % (target, name))
|
||||
|
||||
def brew_install(self, name: str):
|
||||
if not self.cmd_exist(name):
|
||||
run("brew install "+name)
|
||||
|
||||
|
||||
class Installer(Base):
|
||||
def doInit(self, val: str):
|
||||
if val == "":
|
||||
print("install value is empty")
|
||||
exit()
|
||||
|
||||
install_map = {
|
||||
"brew": self.install_brew,
|
||||
"neovim": self.install_neovim,
|
||||
"nvim": self.install_neovim,
|
||||
"z": self.install_z,
|
||||
"git": self.install_git,
|
||||
"go": self.install_go,
|
||||
"tmux": self.init_tmux,
|
||||
}
|
||||
if val in install_map:
|
||||
install_map.get(val)()
|
||||
else:
|
||||
print("cmd not support, install: "+val)
|
||||
|
||||
# install neovim
|
||||
def install_neovim(self):
|
||||
self.brew_install("neovim")
|
||||
self.check_link(home_dir+"/.config/nvim", dotfile_dir+"/nvim")
|
||||
|
||||
def install_z(self):
|
||||
if not os.path.exists("/usr/local/z.lua"):
|
||||
run("git clone --depth=1 https://github.com/skywind3000/z.lua.git /usr/local/z.lua")
|
||||
|
||||
def install_git(self):
|
||||
self.brew_install("git")
|
||||
self.check_link(home_dir+"/.gitconfig", home_dir +
|
||||
"/.dotfile/git/.gitconfig")
|
||||
|
||||
def install_go(self):
|
||||
self.brew_install("go")
|
||||
cwd = os.getcwd()
|
||||
os.chdir("/usr/local")
|
||||
if os.path.exists("/usr/local/opt/go/libexec"):
|
||||
run("sudo mv go go_old")
|
||||
run("sudo ln -s /usr/local/opt/go/libexec /usr/local/go")
|
||||
os.chdir(cwd)
|
||||
self.brew_install("gopls")
|
||||
self.brew_install("golanglint-ci")
|
||||
|
||||
def install_brew(self):
|
||||
run("/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"")
|
||||
|
||||
def init_tmux(self):
|
||||
self.brew_install("git")
|
||||
self.check_link(home_dir+"/.tmux.conf",
|
||||
home_dir+"/.dotfile/.tmux.conf")
|
||||
if not os.path.exists(home_dir+"/.tmux/plugins/tmux-resurrect"):
|
||||
run("git clone --depth=1 https://github.com/tmux-plugins/tmux-resurrect %s/.tmux/plugins/tmux-resurrect" % (home_dir))
|
||||
|
||||
|
||||
def run(cmd: str):
|
||||
|
||||
Reference in New Issue
Block a user