Installing thoughtbot dotfiles on GitHub Codespaces

Consulting for large clients that have apps with complex stacks has us working with Github Codespaces more frequently. Codespaces has a tight integration with Visual Studio Code if that’s your jam, but I personally use neovim, tmux, and a fork of the thoughtbot dotfiles manged by rcm for my development envrionment. Thankfully Github has made it straightforward to personalize your codespace and upload your dotfiles. If you set your dotfiles repository in your Github Codespace settings, Github will automatically copy your dotfiles to Codespaces you create. Now all you have to do is create a install script within your dotfiles repository, and Github will run the script after it clones your dotfiles to the Codespace to setup your environment.


if [ -z "$USER" ]; then
  USER=$(id -un)

mv /workspaces/.codespaces/.persistedshare/dotfiles $HOME/dotfiles

cd $HOME

# Make passwordless sudo work
export SUDO_ASKPASS=/bin/true

# Change shell to zsh
sudo chsh "$(id -un)" --shell "/usr/bin/zsh"

# Install ag for fast searching
sudo apt-get install -y silversearcher-ag

# Install rcm for Ubuntu > 19
sudo apt-get update
sudo apt-get install -y rcm
yes | rcup -d dotfiles -x -x LICENSE -x Brewfile -x install

This install script copies the dotfiles to the home directory, makes it so you can run sudo commands without a password, changes the default shell to zsh, installs the packages silversearcher-ag and rcm, and finally installs the dotfiles using rcm. That’s it, now when you ssh to the Codespace server you will have all your tools just like if you were working on your local machine.

Your mileage may vary and you will likely need to tweak the script some. For example the client I’m working with currently includes neovim in their codespace image, but you could install it via your dotfiles install script if needed.

# Install neovim
sudo apt-get install -y libfuse2
# We use the app image to get the latest version, you could install
# through apt like the other packages in the install script, but it's
# likely an old verion.
curl -L -o $HOME/bin/nvim
chmod a+x $HOME/bin/nvim