diff options
author | Patrick Spek <p.spek@tyil.nl> | 2023-12-11 14:28:10 +0100 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2023-12-11 14:28:10 +0100 |
commit | db9b0cad45d8fd3312c071050a4cffb4340fcbe1 (patch) | |
tree | 0bf457ed35228289bdfd915dc0be3f30475b591f | |
parent | eb77cd16400adcad2c110f314dbc74a04ead31d0 (diff) |
Add small script to update dotfiles
-rwxr-xr-x | .local/bin/updot | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/.local/bin/updot b/.local/bin/updot new file mode 100755 index 0000000..f0179ad --- /dev/null +++ b/.local/bin/updot @@ -0,0 +1,63 @@ +#!/bin/sh + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. + +main() +{ + DOTFILES_REMOTE="origin" + DOTFILES_BRANCH="master" + + # Handle opts + while getopts ":h" opt + do + case "$opt" in + b) DOTFILES_BRANCH="$OPTARG" ;; + h) usage && exit 0 ;; + u) DOTFILES_REMOTE="$OPTARG" ;; + *) + printf "Invalid option passed: %s\n" "$OPTARG" >&2 + ;; + esac + done + + shift $(( OPTIND - 1 )) + + # Stash any pending changes + git -C "$HOME" stash + + # Update the main repository + git -C "$HOME" fetch "$DOTFILES_REMOTE" "$DOTFILES_BRANCH" + git -C "$HOME" reset --hard "$DOTFILES_REMOTE/$DOTFILES_BRANCH" + + # Pull updates for all submodules + git -C "$HOME" submodule update --init --recursive --remote + + # Apply the stash + git -C "$HOME" stash apply +} + +usage() +{ + cat <<EOF +Usage: + ${0##*/} -h + ${0##*/} [-b <branch>] [-u <remote>] + +Utility application for dotfile maintenance. + +Options: + -b The name of the branch to use, defaults to "master" + -h Show this help text and exit. + -u The name of the remote to use, defaults to "origin" +EOF +} + +main "$@" |