mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
208 lines
5.8 KiB
Bash
Executable File
208 lines
5.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Dotfiles manager and install helper
|
|
# (c) Ismo Vuorinen <https://github.com/ivuorinen> 2022
|
|
# Licensed under MIT, see LICENSE
|
|
#
|
|
# shellcheck source-path=$HOME/.dotfiles/local/bin
|
|
#
|
|
# Helper variables, override with ENVs like `VERBOSE=1 dfm help`
|
|
: "${VERBOSE:=0}"
|
|
: "${DOTFILES:=$HOME/.dotfiles}"
|
|
: "${INSTALL_SCRIPT:=$DOTFILES/scripts/install-dotfiles.sh}"
|
|
: "${BREWFILE:=$DOTFILES/Brewfile}"
|
|
: "${HOSTFILES:=$DOTFILES/hosts}"
|
|
|
|
SCRIPT=$(basename "$0")
|
|
|
|
# shellcheck source=./../../scripts/shared.sh
|
|
source "$DOTFILES/scripts/shared.sh"
|
|
|
|
function section_install
|
|
{
|
|
USAGE_PREFIX="$SCRIPT install"
|
|
|
|
case "$1" in
|
|
all)
|
|
$0 install antigen
|
|
$0 install starship
|
|
$0 install macos
|
|
$0 install npm
|
|
;;
|
|
antigen)
|
|
curl -L git.io/antigen > "$DOTFILES/local/bin/antigen.zsh" && msg_done "🎉 New antigen installed!"
|
|
;;
|
|
starship)
|
|
curl -sS https://starship.rs/install.sh | sh && msg_done "🎉 starship installed!"
|
|
;;
|
|
macos)
|
|
bash "$DOTFILES/scripts/set-macos-defaults.sh" && msg_done "🎉 Brewfile defined apps has been installed!"
|
|
;;
|
|
npm)
|
|
bash "$DOTFILES/scripts/install-npm-packages.sh" && msg_done "NPM Packages have been installed!"
|
|
;;
|
|
settler)
|
|
bash "$DOTFILES/scripts/settler.sh" && msg_done "🎉 Settler has been run!"
|
|
;;
|
|
*)
|
|
menu_section "$USAGE_PREFIX" "all | antigen | starship | npm | macos | settler"
|
|
menu_item "all" "Installs antigen, macos, brew and ext_gh"
|
|
menu_item "antigen" "Updates the antigen.zsh file"
|
|
menu_item "starship" "Install starship.rs"
|
|
menu_item "npm" "Install NPM Packages"
|
|
menu_item "macos" "Setup nice macOS defaults"
|
|
menu_item "settler" "Runs the WIP settler.sh"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
function section_brew
|
|
{
|
|
USAGE_PREFIX="$SCRIPT brew"
|
|
|
|
if ! command -v brew &> /dev/null; then
|
|
menu_section "$USAGE_PREFIX" "brew not available on this system"
|
|
else
|
|
case "$1" in
|
|
install)
|
|
brew bundle install --file="$BREWFILE" && msg_done "🎉 Done!"
|
|
;;
|
|
update)
|
|
brew update && brew outdated && brew upgrade && brew cleanup
|
|
msg_done "🎉 Done!"
|
|
;;
|
|
updatebundle)
|
|
# Updates .dotfiles/Brewfile with descriptions
|
|
brew bundle dump \
|
|
--force \
|
|
--file="$BREWFILE" \
|
|
--describe && msg_done "🎉 Done!"
|
|
;;
|
|
autoupdate)
|
|
brew autoupdate delete
|
|
brew autoupdate start 43200 --upgrade --cleanup --immediate
|
|
;;
|
|
*)
|
|
menu_section "$USAGE_PREFIX" "install | update | updatebundle | autoupdate"
|
|
menu_item "install" "Installs items defined in Brewfile"
|
|
menu_item "update" "Updates and upgrades brew packages"
|
|
menu_item "updatebundle" "Updates Brewfile with descriptions"
|
|
menu_item "autoupdate" "Setups brew auto-update and runs it immediately"
|
|
;;
|
|
esac
|
|
fi
|
|
}
|
|
|
|
function section_dotfiles
|
|
{
|
|
USAGE_PREFIX="$SCRIPT dotfiles"
|
|
|
|
case "$1" in
|
|
reset_all)
|
|
msg_ok "Running all reset commands"
|
|
$0 dotfiles reset_nvim
|
|
;;
|
|
reset_nvim)
|
|
rm -rf \
|
|
~/.local/share/nvim \
|
|
~/.local/state/nvim \
|
|
~/.cache/nvim \
|
|
~/.config/astronvim \
|
|
~/.config/nvim
|
|
msg_ok "Deleted old nvim files"
|
|
ln -s ~/.dotfiles/config/astronvim ~/.config/astronvim
|
|
ln -s ~/.dotfiles/config/nvim ~/.config/nvim
|
|
msg_ok "Linked nvim and astronvim"
|
|
hash npm 2>/dev/null && $0 install npm
|
|
msg_ok "Installed packages"
|
|
msg_done "...and we are done!"
|
|
;;
|
|
shfmt)
|
|
# Format shell scripts according to following rules.
|
|
find "$DOTFILES" \
|
|
\( -name '*.sh' -or -name '*.zsh' -or -name 'x-*' -or -not '*.pl' \) \
|
|
-exec shfmt -fn -l -w -i 2 -ci -sr -bn {} \;
|
|
msg_done "🎉 dotfiles have been formatted!"
|
|
;;
|
|
*)
|
|
menu_section "$USAGE_PREFIX" "reset_all | reset_nvim | shfmt"
|
|
menu_item "reset_all" "Reset everything, runs all configured reset actions"
|
|
menu_item "reset_nvim" "Resets nvim. Deletes caches, removes nvim folders and relinks nvim folders"
|
|
menu_item "shfmt" "Run shfmt to all dotfiles"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
function section_check
|
|
{
|
|
USAGE_PREFIX="$SCRIPT check"
|
|
X_HOSTNAME=$(hostname)
|
|
X_ARCH=$(uname)
|
|
|
|
case "$1" in
|
|
a|arch)
|
|
[[ "$2" = "" ]] && echo "$X_ARCH" && exit 0
|
|
[[ $X_ARCH = "$2" ]] && exit 0 || exit 1
|
|
;;
|
|
h|host|hostname)
|
|
[[ "$2" = "" ]] && echo "$X_HOSTNAME" && exit 0
|
|
[[ $X_HOSTNAME = "$2" ]] && exit 0 || exit 1
|
|
;;
|
|
*)
|
|
menu_section "$USAGE_PREFIX" "arch | host"
|
|
menu_item "arch <arch>" "Empty returns current. Exit code 0 when match, 1 when not."
|
|
menu_item "host <host>" "Empty returns current. Exit code 0 when match, 1 when not."
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Secret menu for visual tests
|
|
function section_tests
|
|
{
|
|
USAGE_PREFIX="$SCRIPT tests"
|
|
|
|
case "$1" in
|
|
msg)
|
|
msg "msg"
|
|
msg_done "msg_done"
|
|
msg_prompt "msg_prompt"
|
|
msg_prompt_done "msg_prompt_done"
|
|
msg_nested "msg_nested"
|
|
msg_nested_done "msg_nested_done"
|
|
msg_run "msg_run" "second_param"
|
|
msg_ok "msg_ok"
|
|
msg_warn "msg_warn"
|
|
msg_err "msg_err"
|
|
;;
|
|
*)
|
|
menu_section "$USAGE_PREFIX" "msg"
|
|
menu_item "msg" "List all log functions from shared.sh"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
function usage
|
|
{
|
|
echo ""
|
|
menu_section "Usage: $SCRIPT" "install | reset | brew | check | dotfiles"
|
|
echo $" All commands have their own subcommands."
|
|
echo ""
|
|
section_install
|
|
echo ""
|
|
section_brew
|
|
echo ""
|
|
section_check
|
|
echo ""
|
|
section_dotfiles
|
|
}
|
|
|
|
# The main loop. first keyword after $0 triggers section, or help.
|
|
case "$1" in
|
|
install) section_install "$2" ;;
|
|
brew) section_brew "$2" ;;
|
|
check) section_check "$2" ;;
|
|
dotfiles) section_dotfiles "$2" ;;
|
|
tests) section_tests "$2" ;;
|
|
*) usage && exit 0 ;;
|
|
esac
|