Skip to content

Commit

Permalink
error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
icebarf committed Jun 25, 2023
1 parent ca77abb commit 1bcec9f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions dotmg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# Internal variable that will refer to the $HOME directory
[[ -z "$HOUSE" ]] && declare -g HOUSE=$HOME
Expand All @@ -19,15 +19,21 @@ strip-all() {
# dotmg implementation

# utilities
write-base-gitignore() {
printf "/*\n" > .gitignore
}

error () {
printf "dotmg: %s" "$@"
printf "dotmg: %s\n" "$@"
exit
}

check-gitignore-exists() {
[[ ! (-r ".gitignore" && -w ".gitignore") ]] && \
error ".gitignore does not exist. Please generate it using init-gitignore or init commands."
}

write-base-gitignore() {
printf "/*\n" > .gitignore
}

dont-ignore-this-dir() {
mapfile -t gitignore < .gitignore
for line in "${gitignore[@]}"; do
Expand Down Expand Up @@ -65,14 +71,15 @@ remove-lines-after() {
# dotmg

dotmg-init() {
cd "$1" || error "init failed\n"
cd "$1" || error "init failed"
git init
git branch -m main
write-base-gitignore
}

dotmg-dont-ignore() {
cd "$HOUSE" || error "could not switch to $HOME"
cd "$HOUSE" || error "could not switch to ${HOUSE}"
check-gitignore-exists
dirlist=""
for arg in "$@"; do
declare -a dirs
Expand Down Expand Up @@ -114,7 +121,7 @@ dotmg-run () {
[[ "$1" == "init" ]] && dotmg-init "$HOUSE" && exit 0
[[ "$1" == "init-gitignore" ]] && write-base-gitignore && exit 0
[[ "$1" == "add" ]] && shift && dotmg-dont-ignore "$@" && remove-empty-newlines && exit 0
[[ "$1" == "clean-newlines" ]] && remove-empty-newlines && exit 0 # seems useless right now. might remove later.
[[ "$1" == "clean-newlines" ]] && check-gitignore-exists && remove-empty-newlines && exit 0 # seems useless right now. might remove later.
}

dotmg-run "$@"

0 comments on commit 1bcec9f

Please sign in to comment.