From db9b0cad45d8fd3312c071050a4cffb4340fcbe1 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 11 Dec 2023 14:28:10 +0100 Subject: Add small script to update dotfiles --- .local/bin/updot | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 .local/bin/updot 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 <] [-u ] + +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 "$@" -- cgit v1.1