From 62945bd4b65d5b3aeda68be4a1192b2b50acfb5f Mon Sep 17 00:00:00 2001 From: Yinzuo Jiang Date: Sun, 1 Sep 2024 10:43:51 +0800 Subject: [PATCH] fix: SUDO variable in install scripts, vim-go for gomod ft --- install/build_cmake.sh | 9 +++++---- install/build_nvim.sh | 9 +++++---- install/build_satanson_ag.sh | 11 ++++++----- install/build_tmux.sh | 9 +++++---- install/build_vim.sh | 9 +++++---- install/git.sh | 17 ++++++++++++++--- install/ubuntu.sh | 36 ++++++++++++++++++++++-------------- root/.vim/doc/golang.txt | 10 ++++++++++ root/.vim/vimrc.d/golang.vim | 13 +------------ 9 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 root/.vim/doc/golang.txt diff --git a/install/build_cmake.sh b/install/build_cmake.sh index b66a5b3..dbfbb9d 100755 --- a/install/build_cmake.sh +++ b/install/build_cmake.sh @@ -1,16 +1,17 @@ #!/bin/bash +. install/git.sh + commit=$1 -apt-get -y install libssl-dev +$SUDO apt-get -y install libssl-dev function _uninstall() { - make uninstall + $SUDO make uninstall } function _install() { - ./bootstrap && make && make install + ./bootstrap && make && $SUDO make install } -. install/git.sh main https://gitlab.kitware.com/cmake/cmake.git cmake $commit diff --git a/install/build_nvim.sh b/install/build_nvim.sh index 6819996..8ba5090 100755 --- a/install/build_nvim.sh +++ b/install/build_nvim.sh @@ -1,20 +1,21 @@ #!/bin/bash +. install/git.sh + PYTHON=/usr/bin/python3 commit=$1 -apt-get -y install ninja-build gettext libtool libtool-bin autoconf automake cmake g++ pkg-config unzip +$SUDO apt-get -y install ninja-build gettext libtool libtool-bin autoconf automake cmake g++ pkg-config unzip $PYTHON -m pip install -U neovim function _uninstall() { - cmake --build build/ --target uninstall + $SUDO cmake --build build/ --target uninstall } function _install() { make CMAKE_BUILD_TYPE=RelWithDebInfo - make install + $SUDO make install } -. install/git.sh main https://github.com/neovim/neovim.git neovim $commit diff --git a/install/build_satanson_ag.sh b/install/build_satanson_ag.sh index fd3dcdd..acb8db7 100755 --- a/install/build_satanson_ag.sh +++ b/install/build_satanson_ag.sh @@ -1,21 +1,22 @@ #!/bin/bash +. install/git.sh + commit=$1 if [ -x "$(command -v apt)" ]; then - apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev + $SUDO apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev elif [ -x "$(command -v yum)" ]; then - yum -y install pkgconfig automake gcc zlib-devel pcre-devel xz-devel + $SUDO yum -y install pkgconfig automake gcc zlib-devel pcre-devel xz-devel fi function _uninstall() { - make uninstall + $SUDO make uninstall } function _install() { ./build.sh - make install + $SUDO make install } -. install/git.sh main https://github.com/satanson/the_silver_searcher the_silver_searcher $commit diff --git a/install/build_tmux.sh b/install/build_tmux.sh index 27016b7..e34c752 100755 --- a/install/build_tmux.sh +++ b/install/build_tmux.sh @@ -1,18 +1,19 @@ #!/bin/bash +. install/git.sh + commit=$1 -apt-get install libevent-dev ncurses-dev build-essential bison pkg-config automake +$SUDO apt-get install libevent-dev ncurses-dev build-essential bison pkg-config automake function _uninstall() { - make uninstall + $SUDO make uninstall } function _install() { sh autogen.sh ./configure && make - make install + $SUDO make install } -. install/git.sh main https://github.com/tmux/tmux.git tmux $commit diff --git a/install/build_vim.sh b/install/build_vim.sh index df87f4c..42a7f66 100755 --- a/install/build_vim.sh +++ b/install/build_vim.sh @@ -1,20 +1,21 @@ #!/bin/bash +. install/git.sh + commit=$1 MAKE_FLAG=${MAKE_FLAG:-"-j$((`nproc`-2))"} -apt-get -y install libgtk-3-dev libxt-dev libncurses-dev +$SUDO apt-get -y install libgtk-3-dev libxt-dev libncurses-dev function _uninstall() { - make uninstall + $SUDO make uninstall } function _install() { ./configure --with-features=huge --enable-fontset=yes --enable-cscope=yes --enable-multibyte --enable-python3interp=yes --with-python3-config-dir --enable-gui --with-x make ${MAKE_FLAG} - make install + $SUDO make install } -. install/git.sh main https://github.com/vim/vim.git vim $commit diff --git a/install/git.sh b/install/git.sh index af5bb99..06d166a 100755 --- a/install/git.sh +++ b/install/git.sh @@ -1,12 +1,23 @@ #!/bin/bash +if command -v sudo >/dev/null 2>&1; then + # sudo 命令存在,使用sudo执行命令 + SUDO=sudo +else + # sudo 命令不存在,直接执行命令 + SUDO= +fi + function git_clone_and_cd() { local url=$1 local repo=$2 # git clone first if not exist if [ ! -d $repo ]; then - ( set -v; git clone --no-checkout --depth=1 $url $repo ) + ( + set -v + git clone --no-checkout --depth=1 $url $repo + ) cd $repo else cd $repo @@ -24,9 +35,9 @@ function main() { local url=$1 local repo=$2 local commit=$3 - build_dir=`pwd`/build + build_dir=$(pwd)/build mkdir -p $build_dir - chmod 777 $build_dir + $SUDO chmod 777 $build_dir cd $build_dir git_clone_and_cd $url $repo git_fetch_and_reset $commit diff --git a/install/ubuntu.sh b/install/ubuntu.sh index 9d0cbcc..d17da6f 100755 --- a/install/ubuntu.sh +++ b/install/ubuntu.sh @@ -3,8 +3,16 @@ set -e; -apt-get update -apt-get install -y lsb-release software-properties-common python3-pip +if command -v sudo >/dev/null 2>&1; then + # sudo 命令存在,使用sudo执行命令 + SUDO=sudo +else + # sudo 命令不存在,直接执行命令 + SUDO= +fi + +$SUDO apt-get update +$SUDO apt-get install -y lsb-release software-properties-common python3-pip UBUNTU_CODE_NAME=$(lsb_release -c | cut -f2) UBUNTU_VERSION=$(lsb_release -r | cut -f2) @@ -17,7 +25,7 @@ function install_tmux() { if [[ $UBUNTU_VERSION == "18.04" ]]; then ./install/build_tmux.sh else - apt-get install -y tmux + $SUDO apt-get install -y tmux fi } @@ -25,8 +33,8 @@ function install_nvim() { if [[ $UBUNTU_VERSION == "18.04" ]]; then ./install/build_nvim.sh $NVIM_COMMIT else - add-apt-repository ppa:neovim-ppa/unstable - apt-get install -y neovim + $SUDO add-apt-repository ppa:neovim-ppa/unstable + $SUDO apt-get install -y neovim pip3 install neovim fi } @@ -42,8 +50,8 @@ function install_llvm() { deb ${LLVM_URL}/$UBUNTU_CODE_NAME/ llvm-toolchain-$UBUNTU_CODE_NAME${LLVM_VERSION} main deb-src ${LLVM_URL}/$UBUNTU_CODE_NAME/ llvm-toolchain-$UBUNTU_CODE_NAME${LLVM_VERSION} main EOF - apt-get update - apt-get install -y clangd${LLVM_VERSION} clang-tidy${LLVM_VERSION} clang-format${LLVM_VERSION} clang${LLVM_VERSION} + $SUDO apt-get update + $SUDO apt-get install -y clangd${LLVM_VERSION} clang-tidy${LLVM_VERSION} clang-format${LLVM_VERSION} clang${LLVM_VERSION} } function install_rg() { @@ -54,9 +62,9 @@ function install_rg() { # 下载.deb文件(ripgrep_14.1.0-1_amd64.deb 可以用) mkdir -p build wget --directory-prefix build https://github.com/BurntSushi/ripgrep/releases/download/14.1.0/ripgrep_14.1.0-1_amd64.deb - dpkg -i build/ripgrep_14.1.0-1_amd64.deb + $SUDO dpkg -i build/ripgrep_14.1.0-1_amd64.deb else - apt-get install -y ripgrep + $SUDO apt-get install -y ripgrep fi } @@ -68,7 +76,7 @@ function install_fd() { 运行 dpkg -i .deb 安装 fd " else - apt-get install -y fd-find + $SUDO apt-get install -y fd-find ln -s $(which fdfind) $HOME/.local/bin/fd prompt=$prompt" === fd === @@ -82,7 +90,7 @@ function install_other_apt_packages() { # Leaderf needs python3-dev and python3-distutils # wamerican: American English字典文件,安装后位于/usr/share/dict/american-english, 用于vim dictionary # wordnet: nvim cmp dictionary 可以用wordnet解释单词 - apt-get install -y curl less tree bd bat git cmake sqlformat python3-dev python3-distutils wamerican wordnet + $SUDO apt-get install -y curl less tree bd bat git cmake sqlformat python3-dev python3-distutils wamerican wordnet shfmt # ripgrep-all(master分支) # See: https://github.com/phiresky/ripgrep-all/issues/113 @@ -112,7 +120,7 @@ function install_vim() { # apt-get install -y libgtk-3-dev libxt-dev vim-gtk3 # update-alternatives --config vim # update-alternatives --install /usr/bin/vim vim /usr/local/bin/vim 100 - apt-get -y install libgtk-3-dev libxt-dev + $SUDO apt-get -y install libgtk-3-dev libxt-dev ./install/build_vim.sh $VIM_COMMIT } @@ -133,7 +141,7 @@ _go_installged=false function install_go() { if [ "$_go_installed" = false ]; then _go_installed=true - snap install go --classic + $SUDO snap install go --classic prompt=$prompt" === Go === 必须确保GOPATH/bin在环境变量,保证gopls能找到。 @@ -145,7 +153,7 @@ function install_go() { function install_gvm() { install_go - apt-get -y install curl git mercurial make binutils bison gcc build-essential + $SUDO apt-get -y install curl git mercurial make binutils bison gcc build-essential bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) prompt=$prompt" === GVM === diff --git a/root/.vim/doc/golang.txt b/root/.vim/doc/golang.txt new file mode 100644 index 0000000..ec839fd --- /dev/null +++ b/root/.vim/doc/golang.txt @@ -0,0 +1,10 @@ +vim:ft=help + +*golang.txt* + +1. `godef`:godef 是 Go 语言的一个老工具,可以快速找到定义的位置。它的优点是简单快捷,但缺点是功能相对单一,不支持如代码提示、重构和诊断等功能。 +2. `guru`:guru 提供了更多高级功能,如查找所有引用、查找接口实现等。然而,它的使用相对更复杂,也需要更多的计算资源。 +3. `gopls`:gopls 是 Go 团队发布的官方语言服务器,功能最为全面,包括代码自动完成、查找定义、重构、诊断等。由于是官方工具,与最新的 Go 语言特性和改动的兼容性也最好。然而,它可能会比较消耗计算资源。 + +现在来看,`gopls`可能是最全面且最实用的选择。作为官方的 Go 语言服务器,它可以提供全面的 IDE 功能,并且可以完全兼容最新的 Go 语言特性。然而,如果你只需要一些简单的功能,比如快速查找定义,那么`godef`可能就足够了。而`guru`则介于两者之间,提供了一些更高级的功能,但也更复杂一些。 + diff --git a/root/.vim/vimrc.d/golang.vim b/root/.vim/vimrc.d/golang.vim index 83bb61c..0b0120b 100644 --- a/root/.vim/vimrc.d/golang.vim +++ b/root/.vim/vimrc.d/golang.vim @@ -1,15 +1,4 @@ -" 1. `godef`:godef 是 Go 语言的一个老工具,可以快速找到定义的位置。它的优点是简单快捷,但缺点是功能相对单一,不支持如代码提示、重构和诊断等功能。 -" -" 2. `guru`:guru 提供了更多高级功能,如查找所有引用、查找接口实现等。然而,它的使用相对更复杂,也需要更多的计算资源。 -" -" 3. `gopls`:gopls 是 Go 团队发布的官方语言服务器,功能最为全面,包括代码自动完成、查找定义、重构、诊断等。由于是官方工具,与最新的 Go 语言特性和改动的兼容性也最好。然而,它可能会比较消耗计算资源。 -" -" 现在来看,`gopls`可能是最全面且最实用的选择。作为官方的 Go 语言服务器,它可以提供全面的 IDE 功能,并且可以完全兼容最新的 Go 语言特性。然而,如果你只需要一些简单的功能,比如快速查找定义,那么`godef`可能就足够了。而`guru`则介于两者之间,提供了一些更高级的功能,但也更复杂一些。 -" - -" Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries', 'for': 'go' } -" rg -oIN Go[a-zA-Z]+ commands.vim -Plug 'fatih/vim-go', { 'on': ['GoRename', 'GoGuruScope', 'GoPointsTo', 'GoWhicherrs', 'GoCallees', 'GoDescribe', 'GoCallstack', 'GoFreevars', 'GoChannelPeers', 'GoImplements', 'GoReferrers', 'GoSameIds', 'GoSameIdsClear', 'GoSameIdsToggle', 'GoSameIdsAutoToggle', 'GoCallers', 'GoAddTags', 'GoRemoveTags', 'GoModFmt', 'GoFiles', 'GoDeps', 'GoInfo', 'GoAutoTypeInfoToggle', 'GoBuild', 'GoBuildTags', 'GoGenerate', 'GoRun', 'GoInstall', 'GoTest', 'GoTestCompile', 'GoTestFile', 'GoTestFunc', 'GoCoverage', 'GoCoverageClear', 'GoCoverageToggle', 'GoCoverageBrowser', 'GoCoverageOverlay', 'GoPlay', 'GoDef', 'GoDefType', 'GoDefPop', 'GoDefStack', 'GoDefStackClear', 'GoDoc', 'GoDocBrowser', 'GoFmt', 'GoFmtAutoSaveToggle', 'GoImports', 'GoAsmFmtAutoSaveToggle', 'GoDrop', 'GoImport', 'GoImportAs', 'GoMetaLinter', 'Gometa', 'GoMetaLinterAutoSaveToggle', 'GoLint', 'Golint', 'GoVet', 'GoErrCheck', 'GoAlternate', 'GoDecls', 'GoDeclsDir', 'GoImpl', 'GoTemplateAutoCreateToggle', 'GoKeyify', 'GoFillStruct', 'GoDebugStart', 'GoDebugStart', 'GoDebugTest', 'GoDebugTestFunc', 'GoDebugAttach', 'GoDebugConnect', 'GoDebugBreakpoint', 'GoReportGitHubIssue', 'GoIfErr', 'GoAddWorkspace', 'GoLSPDebugBrowser', 'GoDiagnostics', 'GoModReload', 'GoToggleTermCloseOnExit', 'GoExtract']} +Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries', 'for': ['go', 'gomod', 'gosum'] } if v:version >= 801 Plug 'sebdah/vim-delve', { 'for': 'go' } endif