#!/bin/bash # configure reads TITLE and DESCRIPTION # shellcheck disable=SC2034 TITLE="Languages" # shellcheck disable=SC2034 DESCRIPTION="Install programming 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="$CONF_DIR/languages" # mise installs these gems into each Ruby it installs, so Rails is still there # after mise upgrade moves to a new Ruby DEFAULT_GEMS="$HOME/.default-gems" # mise's activation line goes in ~/.bashrc, so the languages it installs are # on PATH in new terminals BASHRC="$HOME/.bashrc" BLOCK_START="# >>> Federated Connector: mise >>>" BLOCK_END="# <<< Federated Connector: mise <<<" # Ruby is built from source, which needs these (from ruby-build's wiki) RUBY_BUILD_DEPS=(build-essential autoconf patch rustc libssl-dev libyaml-dev libreadline-dev zlib1g-dev libgmp-dev libncurses-dev libffi-dev libgdbm-dev libdb-dev uuid-dev) 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" } # From mise's own apt repository, so Pop!_OS' updates keep mise up to date install_mise() { echo "mise isn't installed. It comes from mise's own apt repository (mise.jdx.dev)." confirm_yes "Install it?" || return 1 sudo install -dm 755 /etc/apt/keyrings || return 1 curl -fsSL --max-time 60 https://mise.jdx.dev/gpg-key.pub \ | sudo tee /etc/apt/keyrings/mise-archive-keyring.asc > /dev/null || return 1 echo "deb [signed-by=/etc/apt/keyrings/mise-archive-keyring.asc] https://mise.jdx.dev/deb stable main" \ | sudo tee /etc/apt/sources.list.d/mise.list > /dev/null || return 1 sudo apt-get update && sudo apt-get install -y mise } activated() { grep -qsxF "$BLOCK_START" "$BASHRC" } activate() { { echo echo "$BLOCK_START" echo "# The languages configure languages installs: see mise ls" echo 'eval "$(mise activate bash)"' echo "$BLOCK_END" } >> "$BASHRC" || return 1 echo "Added mise to ~/.bashrc; the languages it installs work in new terminals." } install_rails() { pkg_ensure "Building Ruby" "${RUBY_BUILD_DEPS[@]}" || return 1 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 "mise installs programming languages and tools for you, and the version a" echo "project asks for in its mise.toml." command -v mise > /dev/null || install_mise || return 1 activated || activate || return 1 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. node@lts python@3.13 go@latest, or press Enter for none: " tools for tool in $tools; do echo "Installing $tool..." mise use -g "$tool" || return 1 done echo "To update them: mise upgrade. To remove one later: mise unuse -g " }