Skip to content

Commit

Permalink
fix: SUDO variable in install scripts, vim-go for gomod ft
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Sep 1, 2024
1 parent 68786ee commit 62945bd
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 50 deletions.
9 changes: 5 additions & 4 deletions install/build_cmake.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions install/build_nvim.sh
Original file line number Diff line number Diff line change
@@ -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

11 changes: 6 additions & 5 deletions install/build_satanson_ag.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions install/build_tmux.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions install/build_vim.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 14 additions & 3 deletions install/git.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
36 changes: 22 additions & 14 deletions install/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -17,16 +25,16 @@ 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
}

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
}
Expand All @@ -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() {
Expand All @@ -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
}

Expand All @@ -68,7 +76,7 @@ function install_fd() {
运行 dpkg -i <package_name>.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 ===
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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能找到。
Expand All @@ -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 ===
Expand Down
10 changes: 10 additions & 0 deletions root/.vim/doc/golang.txt
Original file line number Diff line number Diff line change
@@ -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`则介于两者之间,提供了一些更高级的功能,但也更复杂一些。

13 changes: 1 addition & 12 deletions root/.vim/vimrc.d/golang.vim
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 62945bd

Please sign in to comment.