-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvim-install.sh
executable file
·157 lines (120 loc) · 4.3 KB
/
nvim-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
BASE_DIR="$HOME/.var/app/io.neovim.nvim"
function install_fonts() {
[ ! -d "$HOME/.local/share/fonts" ] && mkdir -p "$HOME/.local/share/fonts"
if [[ $(find ~/.local/share/fonts -name *JetBrains* | grep --count -w ".*") -eq 0 ]]; then
TMPFILE=$(mktemp)
wget "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/JetBrainsMono.zip" -O $TMPFILE
unzip -d "$HOME/.local/share/fonts" $TMPFILE
rm $TMPFILE
fi
fc-cache -f
}
function extension() {
echo $(flatpak info --show-sdk io.neovim.nvim | sed "s/Sdk/Sdk.Extension.$1/")
}
function install_pyenv() {
local home=${1:-$HOME}
git clone https://github.com/pyenv/pyenv.git $home/.pyenv
cat <<'EOF' >> $home/.bashrc
# pyenv
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
EOF
}
function install_tfenv() {
local home=${1:-$HOME}
git clone --depth=1 https://github.com/tfutils/tfenv.git $home/.tfenv
echo 'export PATH=$HOME/.tfenv/bin:$PATH' >> $home/.bashrc
}
function install_neovim() {
cwd=$(pwd)
tmpdir=$(mktemp -d)
cd $tmpdir
wget 'https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz'
wget 'https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz.sha256sum'
if [[ -z $(sha256sum -c "$tmpdir/nvim-linux64.tar.gz.sha256sum" 2>&1 | egrep 'OK|SUCESSO') ]]; then
echo 'Neovim SHA256 com falha.'
exit 1
fi
sudo rm -rf /opt/nvim
sudo mkdir -p /opt/nvim
sudo tar --directory=/opt/nvim --file=nvim-linux64.tar.gz --extract --gzip --strip-components=1 nvim-linux64
[[ -z $(cat $HOME/.bashrc | grep '/opt/nvim/bin') ]] && echo 'export PATH=/opt/nvim/bin:$PATH' >> $HOME/.bashrc
cd $cwd
rm -rf $tmpdir
# adiciona a config do nvim
[ ! -L $HOME/config/nvim ] && ln -s $(pwd)/xdg-config/nvim $HOME/.config/
# instala o pyenv
[ ! -d $HOME/.pyenv ] && install_pyenv
# instala o tfenv
[ ! -d $HOME/.tfenv ] && install_tfenv
}
function install_neovim_flatpak() {
# instala o Neovim via flatpak
flatpak install -y flathub io.neovim.nvim
# instala as extensões
flatpak install -y $(extension golang)
flatpak install -y $(extension node20)
flatpak install -y $(extension rust-stable)
# modifica algumas configurações
flatpak --user override \
--socket=ssh-auth \
--env='SHELL=/usr/bin/bash' \
--nofilesystem=host \
--nofilesystem=/tmp \
--nofilesystem=/var/tmp \
--filesystem=~/git \
--filesystem=~/.gitconfig \
--filesystem=~/.ssh \
--persist=.bashrc \
--persist=.bash_history \
--persist=.pyenv \
--persist=.tfenv \
--persist=go \
--persist=.start.sh \
io.neovim.nvim
# adiciona os arquivos do bash
[ ! -f $BASE_DIR/.bashrc ] && touch $BASE_DIR/.bashrc
[ ! -f $BASE_DIR/.bash_history ] && touch $BASE_DIR/.bash_history
# cria as pastas que vamos copiar os arquivos
mkdir -p \
$BASE_DIR/config/ \
$BASE_DIR/data/nvim/mason/bin/ \
$BASE_DIR/go
# adiciona a config do nvim
[ ! -L $BASE_DIR/config/nvim ] && ln -s $(pwd)/xdg-config/nvim $BASE_DIR/config/
# instala o pyenv
[ ! -d $BASE_DIR/.pyenv ] && install_pyenv $BASE_DIR
# instala o tfenv
[ ! -d $BASE_DIR/.tfenv ] && install_tfenv $BASE_DIR
# cria script de inicialização
[ ! -f $BASE_DIR/.start.sh ] && touch $BASE_DIR/.start.sh && chmod +x $BASE_DIR/.start.sh
cat <<'EOF' > $BASE_DIR/.start.sh
#!/usr/bin/bash
# obtém a lista de extensões instaladas
SDK=()
for d in /usr/lib/sdk/*; do
SDK+=("${d##*/}")
done
# habilita as extensões instaladas
for i in "${SDK[@]}"; do
sdk_ext_dir="/usr/lib/sdk/$i"
if [[ -d "$sdk_ext_dir" && -f "$sdk_ext_dir/enable.sh" ]]; then
. "$sdk_ext_dir/enable.sh"
fi
done
# usa os pacotes instalados pelo golang
PATH="$HOME/go/bin:$PATH"
[ -z $(which lazygit) ] && go install github.com/jesseduffield/lazygit@latest
PATH="$XDG_DATA_HOME/cargo/bin:$PATH"
[ -z $(which rg) ] && cargo install ripgrep
# inicia o nvim
/app/bin/nvim-wrapper
EOF
install_fonts
echo 'Adicione o atalho de inicialização:'
echo ' alias nvim="flatpak run --command=$HOME/.start.sh io.neovim.nvim"'
}
install_neovim