Files
coredesktop/configure.d/40-languages.sh
T

63 lines
1.9 KiB
Bash

#!/bin/bash
# configure reads TITLE and DESCRIPTION
# shellcheck disable=SC2034
TITLE="Languages"
# shellcheck disable=SC2034
DESCRIPTION="Install more languages with mise, e.g. Ruby on Rails"
# Records that you've chosen, even if you chose nothing, so this isn't "to do"
LANGUAGES_CONF="$HOME/.config/coredesktop/languages"
# mise installs these gems into each Ruby it installs, so Rails is still there
# after update moves to a new Ruby
DEFAULT_GEMS="$HOME/.default-gems"
is_installed() {
command -v mise > /dev/null
}
is_configured() {
[ -f "$LANGUAGES_CONF" ]
}
# Add a gem to ~/.default-gems unless it's there
add_default_gem() {
grep -qsx "$1" "$DEFAULT_GEMS" || echo "$1" >> "$DEFAULT_GEMS"
}
install_rails() {
echo "Installing Ruby and Rails..."
add_default_gem bundler || return 1
add_default_gem rails || return 1
mise use -g ruby@latest || return 1
# Ruby may already have been installed before ~/.default-gems listed these
mise exec -- gem install --conservative bundler rails || return 1
grep -qsx rails "$LANGUAGES_CONF" || echo rails >> "$LANGUAGES_CONF"
}
run_configure() {
local tools tool
export MISE_YES=1
# From home, so a project's mise.toml in the current directory doesn't count
cd "$HOME" || return 1
echo "Go, Rust, Node.js, Python, Bun and Zig are already installed. mise installs other"
echo "languages for you, and the version a project asks for in its mise.toml."
mkdir -p "$(dirname "$LANGUAGES_CONF")"
touch "$LANGUAGES_CONF" || return 1
if confirm "Install Ruby on Rails?"; then
install_rails || return 1
fi
echo "Anything else? Name tools mise knows (mise registry lists them), with a version,"
read -rp "e.g. java@21 deno@latest, or press Enter for none: " tools
for tool in $tools; do
echo "Installing $tool..."
mise use -g "$tool" || return 1
done
echo "update keeps them up to date. To remove one later: mise unuse -g <tool>"
}