Skip to content

Allow enabling the LazyVIM extras module when installing languages #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions install/terminal/select-dev-language.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ else
languages=$(gum choose "${AVAILABLE_LANGUAGES[@]}" --no-limit --height 10 --header "Select programming languages")
fi

install_extras=$(gum confirm "Would you like to enable the LazyVIM extras plugins (if available) too?" && echo true || echo false)

enable_lazyvim_extras() {
local config_file="$HOME/.config/nvim/lazyvim.json"
local extras=("$@")

local extras_json
extras_json=$(printf '"%s",' "${extras[@]}")
extras_json="[${extras_json%,}]"

# Create config file with empty JSON object if it doesn't exist
if [[ ! -f "$config_file" ]]; then
mkdir -p "$(dirname "$config_file")"
echo '{}' > "$config_file"
fi
touch $config_file

# This is cheating to mimic an in-place editing of files (without a tmp file)...
{ rm "$config_file" && jq --argjson extras "$extras_json" '.extras |= (. + $extras | unique)' >"$config_file"; } <"$config_file"
}

if [[ -n "$languages" ]]; then
for language in $languages; do
case $language in
Expand All @@ -15,16 +36,19 @@ if [[ -n "$languages" ]]; then
;;
Node.js)
mise use --global node@lts
$install_extras && enable_lazyvim_extras "lazyvim.plugins.extras.lang.typescript"
;;
Go)
mise use --global go@latest
$install_extras && enable_lazyvim_extras "lazyvim.plugins.extras.lang.go"
;;
PHP)
sudo add-apt-repository -y ppa:ondrej/php
sudo apt -y install php8.4 php8.4-{curl,apcu,intl,mbstring,opcache,pgsql,mysql,sqlite3,redis,xml,zip}
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --quiet && sudo mv composer.phar /usr/local/bin/composer
rm composer-setup.php
$install_extras && enable_lazyvim_extras "lazyvim.plugins.extras.lang.php"
;;
Python)
mise use --global python@latest
Expand Down
15 changes: 15 additions & 0 deletions uninstall/dev-language.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ else
languages=$(gum choose "${AVAILABLE_LANGUAGES[@]}" --no-limit --height 10 --header "Select programming languages to uninstall")
fi

disable_lazyvim_extras() {
local config_file="$HOME/.config/nvim/lazyvim.json"
local extras=("$@")

local extras_json
extras_json=$(printf '"%s",' "${extras[@]}")
extras_json="[${extras_json%,}]"

# This is cheating to mimic an in-place editing of files (without a tmp file)...
{ rm "$config_file" && jq --argjson extras "$extras_json" '.extras |= (. - $extras)' >"$config_file"; } <"$config_file"
}

if [[ -n $languages ]]; then
for language in $languages; do
case $language in
Expand All @@ -15,14 +27,17 @@ if [[ -n $languages ]]; then
;;
Node.js)
mise uninstall node@lts
disable_lazyvim_extras "lazyvim.plugins.extras.lang.typescript"
;;
Go)
mise uninstall go@latest
disable_lazyvim_extras "lazyvim.plugins.extras.lang.go"
;;
PHP)
sudo apt -y purge php8.4 php8.4-{curl,apcu,intl,mbstring,opcache,pgsql,mysql,sqlite3,redis,xml,zip}
sudo add-apt-repository -y --remove ppa:ondrej/php
sudo rm /usr/local/bin/composer
disable_lazyvim_extras "lazyvim.plugins.extras.lang.php"
;;
Python)
mise uninstall python@latest
Expand Down