Skip to content

Instantly share code, notes, and snippets.

@koji
Last active January 2, 2025 08:09
Show Gist options
  • Save koji/76de324f52e89b10b8c55a22bb87c46e to your computer and use it in GitHub Desktop.
Save koji/76de324f52e89b10b8c55a22bb87c46e to your computer and use it in GitHub Desktop.
a shell script to setup WSL environment
# Install ASDF version manager and plugins
if ! command -v asdf &> /dev/null; then
brew install asdf
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc
fi
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git || true
asdf plugin add python || true
asdf plugin add rust || true
# Install Python build dependencies
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev llvm libncurses-dev \
xz-utils tk-dev libffi-dev liblzma-dev
# Install languages
asdf install nodejs 22.12.0
asdf install python 3.12.0
asdf install rust 1.83.0
sudo apt install -y build-essential curl file git
# Install Homebrew
if ! command -v brew &> /dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Add Homebrew to PATH in Zsh
if ! grep -q 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' ~/.zshrc; then
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc
fi
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# Install essential packages with Homebrew
brew install ffmpeg imagemagick
# Setup Starship prompt
if ! command -v starship &> /dev/null; then
curl -sS https://starship.rs/install.sh | sh
fi
# Add Starship configuration to Zsh
if ! grep -q 'eval "$(starship init zsh)"' ~/.zshrc; then
echo 'eval "$(starship init zsh)"' >> ~/.zshrc
fi
mkdir -p ~/.config
curl -o ~/.config/starship.toml https://raw.githubusercontent.com/koji/my-starship/refs/heads/main/starship.toml
#!/bin/bash
# Update and upgrade system
sudo apt update && sudo apt upgrade -y
# Install Zsh
sudo apt install -y zsh
# need to switch $SHELL manually
# Check if Zsh is installed successfully
if ! command -v zsh &> /dev/null; then
echo "Error: Zsh installation failed. Exiting."
exit 1
fi
# Change default shell to Zsh
if [[ $SHELL != "$(which zsh)" ]]; then
echo "Changing default shell to Zsh..."
if sudo chsh -s "$(which zsh)" "$USER"; then
echo "Default shell changed to Zsh. Restarting the script with Zsh..."
exec zsh -c "$(cat "$0")" # Restart the script with Zsh
exit 0
else
echo "Warning: Failed to change default shell to Zsh. Continuing with Bash..."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment