aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/updot
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/updot')
-rwxr-xr-x.local/bin/updot63
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 "$@"