#!/bin/bash

# Ask for the administrator password upfront
sudo -v

# Keep-alive: update existing `sudo` time stamp until script has finished
while true; do
	sudo -n true
	sleep 60
	kill -0 "$$" || exit
done 2>/dev/null &

cd ~/.dotfiles

# Update Homebrew
brew update
brew outdated
brew upgrade
brew cleanup

# Ruby
gem update --system
gem update
gem cleanup all

# Update tmux plugins
~/.tmux/plugins/tpm/bin/update_plugins all

# Update GitHub extensions
gh extension upgrade --all

# Update Fish plugins
fisher update

# Update Neovim
nvim --headless "+Lazy! sync" +qa

# Update macOS software
sudo softwareupdate -i -a

# Write Homebrew Brewfile
homebrew-backup

# Write preferences
preferences-backup

# Write launch agents
launchagents-backup
