-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvim_config.sh
executable file
·126 lines (107 loc) · 4.54 KB
/
nvim_config.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
#!/bin/bash
echo "Sucessfully called $(basename "$0")"
source "./functions.sh"
temp_file=$1
# Read JSON from the temporary file
[[ -n $temp_file ]] && CONFIG_JSON=$(<"$temp_file")
# For an independent manual run of this script we add packages to an empty CONFIG_JSON
if [[ -z $temp_file ]]; then
CONFIG_JSON_PATH="./config.json"
# Ensure config.json exists
if [[ ! -f "$CONFIG_JSON_PATH" ]]; then
echo "config.json not found in this directory"
exit 1
fi
echo "-----------------------------------------------------------------"
read -p "Would you like to check and install neovim dependencies? (y/n): " answer
if [[ "$answer" = "y" ]]; then
CONFIG_JSON=$(jq '.packages.neovim += {"install": true}' "$CONFIG_JSON_PATH")
fi
read -p "Would you like to check and install kickstart.nvim? (y/n): " answer
if [[ "$answer" = "y" ]]; then
CONFIG_JSON=$(jq '.plugins."kickstart.nvim" += {"install": true}' "$CONFIG_JSON_PATH")
fi
fi
# Function to update the install status in the JSON
update_install_status() {
local plugin="$1"
CONFIG_JSON=$(echo "$CONFIG_JSON" | jq --arg plugin "$plugin" '.plugins[$plugin].install = "handled"')
}
#Install kickstart.nvim if install is true in config.json
if [[ $(echo "$CONFIG_JSON" | jq -r '.plugins."kickstart.nvim".install') == "true" ]]; then
kickstart_dir=$(echo "$CONFIG_JSON" | jq -r '.plugins."kickstart.nvim".directory')
eval kickstart_dir="$kickstart_dir"
if [[ ! -d "$kickstart_dir" ]]; then
echo "Installing kickstart.nvim..."
git clone "$(echo "$CONFIG_JSON" | jq -r '.plugins."kickstart.nvim".url')" "$kickstart_dir"
update_install_status "kickstart.nvim"
else
update_install_status "kickstart.nvim"
echo "kickstart.nvim is already installed."
fi
fi
config_files=$(find -L ~/.config -type f -exec grep -l 'unnamedplus' {} +)
echo "----------------------------------------"
echo "FOUND files with 'unnamedplus':"
echo "$config_files"
echo "----------------------------------------"
# Use a heredoc to store the code block in a variable which is used to activate clipboard over ssh
code_to_add=$(cat <<'EOF'
-- Added by Synology-Homebrew OSC52
vim.g.clipboard = {
name = 'OSC52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
EOF
)
# Check if any files are found
if [[ -n "$config_files" ]]; then
for config_file in $config_files; do
if ! grep -q "Added by Synology-Homebrew OSC52" "$config_file"; then
# Add the code after the line containing "unnamedplus"
func_sed "/unnamedplus/ r /dev/stdin" "$config_file" <<<"$code_to_add"
echo "OSC52 code for remote/system clipbard successfully added to $config_file"
else
echo "OSC52 code for remote/system clipboard already exists in $config_file"
fi
done
else
echo "No file containing 'unnamedplus' found in ~/.config folder."
fi
# Install additional packages for neovim
echo "----------------------------------------"
if [[ -n "$CONFIG_JSON" ]]; then
if [[ $(echo "$CONFIG_JSON" | jq -r '.packages.neovim.install') = true ]]; then
echo "Installing additional neovim components..."
[[ ! $(pip3 show pynvim) ]] && pip3 install pynvim --break-system-packages
echo "npm changes:"
if [[ ! $(command -v npm) ]]; then
echo "npm is not installed. Installing npm..."
brew install npm
fi
# Proceed with npm commands
rm -rf /home/linuxbrew/.linuxbrew/lib/node_modules/npm
brew postinstall node
npm install -g npm@latest
npm config set fund false --location=global
npm install -g neovim@latest
echo
echo -e "Checking for gem updates:\n"
[[ -n $(gem outdated) ]] && gem update
[[ $(gem list neovim -i) ]] && gem install neovim
[[ ! -e ~/.scripts/fzf-git.sh ]] && mkdir -p ~/.scripts && curl -o ~/.scripts/fzf-git.sh https://raw.githubusercontent.com/junegunn/fzf-git.sh/main/fzf-git.sh
else
echo "SKIPPING: neovim components as config.json install flag is set to false."
fi
else
echo "SKIPPING: neovim components installation. This is expected when running this script independently."
fi
# Write updated JSON back to the temporary file
[[ -n $temp_file ]] && echo "$CONFIG_JSON" > "$temp_file"