diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-06 09:54:00 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-06 09:54:00 +0200 |
| commit | fdde3a49d44e7e1404d7665880158a5b84c3dcad (patch) | |
| tree | 94ec9782ba2b2763ee833d75e5a3fb7d581d5017 /dot-backup.sh | |
| parent | 78742f69a5080fe0bdab7dac61400028ee107a37 (diff) | |
| download | dots-backup-fdde3a49d44e7e1404d7665880158a5b84c3dcad.tar.gz dots-backup-fdde3a49d44e7e1404d7665880158a5b84c3dcad.zip | |
Add GIT_REMOTE, GIT_BRANCH config options and --push flag
- GIT_REMOTE in config auto-registers origin on every run (idempotent)
- GIT_BRANCH sets push target branch (defaults to current branch)
- -p/--push pushes after commit; errors if no remote available
- Updated config.example and README
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'dot-backup.sh')
| -rwxr-xr-x | dot-backup.sh | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/dot-backup.sh b/dot-backup.sh index dd40f25..82b6053 100755 --- a/dot-backup.sh +++ b/dot-backup.sh @@ -29,6 +29,8 @@ DEFAULT_OUTPUT_DIR="${HOME}/Programming/GIT/my-dotfiles" LOG_FILE="${HOME}/.local/share/dot-backup/backup.log" DOTFILES_LIST="${HOME}/.config/dot-backup/files.list" CONFIG_FILE="${HOME}/.config/dot-backup/config" +GIT_REMOTE="" +GIT_BRANCH="" # Bootstrap config and log directories on first run FIRST_RUN=false @@ -49,6 +51,7 @@ DRY_RUN=false VERBOSE=false RESTORE=false QUIET=false +PUSH=false usage() { echo "Usage: $0 [options]" @@ -56,6 +59,7 @@ usage() { echo " -v, --verbose Print each file as it is processed" echo " -r, --restore Restore dotfiles from backup to their original locations" echo " -q, --quiet Suppress stdout; write output to log instead" + echo " -p, --push Push to remote after commit (requires GIT_REMOTE in config)" echo " -h, --help Show this help" exit 0 } @@ -66,6 +70,7 @@ for arg in "$@"; do -v|--verbose) VERBOSE=true ;; -r|--restore) RESTORE=true ;; -q|--quiet) QUIET=true ;; + -p|--push) PUSH=true ;; -h|--help) usage ;; *) echo -e "${RED}Unknown option: $arg${NC}"; usage ;; esac @@ -298,7 +303,7 @@ if [[ -d $DEFAULT_OUTPUT_DIR ]]; then if [[ $(git rev-parse --is-inside-work-tree) == "true" ]]; then echo -e "${GREEN}Git Repository already initialized.${NC}" else - echo -e "${YELLOW}Initializing Git Repository. Don't forget to add your remotes.${NC}" + echo -e "${YELLOW}Initializing Git Repository.${NC}" git init git add . fi @@ -307,13 +312,29 @@ else if [[ "$DRY_RUN" == false ]]; then echo -e "${YELLOW}creating our backup directories${NC}" mkdir -p $DEFAULT_OUTPUT_DIR/{home,system} - echo -e "${YELLOW}Initializing Git Repository. Don't forget to add your remotes.${NC}" + echo -e "${YELLOW}Initializing Git Repository.${NC}" cd $DEFAULT_OUTPUT_DIR git init git add . fi fi +# Ensure remote is registered if GIT_REMOTE is configured +if [[ -n "$GIT_REMOTE" && "$DRY_RUN" == false ]]; then + cd $DEFAULT_OUTPUT_DIR + if git remote get-url origin &>/dev/null; then + current=$(git remote get-url origin) + if [[ "$current" != "$GIT_REMOTE" ]]; then + echo -e "${YELLOW}Updating remote origin: $GIT_REMOTE${NC}" + git remote set-url origin "$GIT_REMOTE" + fi + else + echo -e "${YELLOW}Adding remote origin: $GIT_REMOTE${NC}" + git remote add origin "$GIT_REMOTE" + fi + cd $WORKDIR +fi + if [[ "$DRY_RUN" == false ]]; then lastupdate fi @@ -360,6 +381,17 @@ else echo -e "${GREEN}Committed.${NC}" fi +if [[ "$PUSH" == true ]]; then + if [[ -z "$GIT_REMOTE" ]] && ! git remote get-url origin &>/dev/null; then + echo -e "${RED}--push requested but no remote configured. Set GIT_REMOTE in config.${NC}" + exit 1 + fi + branch="${GIT_BRANCH:-$(git symbolic-ref --short HEAD)}" + echo -e "${GREEN}Pushing to origin/$branch...${NC}" + git push origin "$branch" + echo -e "${GREEN}Pushed.${NC}" +fi + echo -e $NC cd $WORKDIR if [[ "$QUIET" == true ]]; then echo "Log written to: $LOG_FILE" >&3; fi |
