diff --git a/dl_dot.sh b/dl_dot.sh new file mode 100644 index 0000000..5ad917a --- /dev/null +++ b/dl_dot.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +# ERR Trap Inheritance by shell functions, command substitutions, and subshells. +set -E + +# Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error. +set -e + +# Treats the use of undefined variables as an error, causing the script to exit. +set -u + +# Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails. +set -o pipefail + +# Cleaup script. +trap cleanup SIGINT SIGTERM ERR EXIT + +# Get the script location and cd to it. +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) + +# Usage error message. +usage() { + cat <&2 -e "${1-}" +} + +# Script exit implementation. +die() { + local msg=$1 + local code=${2-1} # default exit status 1 + msg "\033[0;31m$msg\033[0m" + exit "$code" +} + +# Parameter parsing implementation. +parse_params() { + + while :; do + case "${1-}" in + -h | --help) usage ;; + -v | --verbose) set -x ;; + --no-color) NO_COLOR=1 ;; + -?*) die "Unknown option: $1" ;; + *) break ;; + esac + shift + done + + args=("$@") + + + return 0 +} +# ----- Script Start ----- +# Parse parameters and setup colors for script. +parse_params "$@" +setup_colors + +# Script logic example here. +git clone --bare https://myrepos.dev/Randy-Jordan/dot.git $HOME/.dot +function config { + /usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME $@ +} +mkdir -p .config-backup +config checkout +if [ $? = 0 ]; then + echo "Checked out config."; + else + echo "Backing up pre-existing dot files."; + config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{} +fi; +config checkout +config config status.showUntrackedFiles no + +exit 0 diff --git a/init_dot.sh b/init_dot.sh new file mode 100644 index 0000000..2cd2870 --- /dev/null +++ b/init_dot.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +# ERR Trap Inheritance by shell functions, command substitutions, and subshells. +set -E + +# Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error. +set -e + +# Treats the use of undefined variables as an error, causing the script to exit. +set -u + +# Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails. +set -o pipefail + +# Cleaup script. +trap cleanup SIGINT SIGTERM ERR EXIT + +# Get the script location and cd to it. +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) + +# Usage error message. +usage() { + cat <&2 -e "${1-}" +} + +# Script exit implementation. +die() { + local msg=$1 + local code=${2-1} # default exit status 1 + msg "\033[0;31m$msg\033[0m" + exit "$code" +} + +# Parameter parsing implementation. +parse_params() { + + while :; do + case "${1-}" in + -h | --help) usage ;; + -v | --verbose) set -x ;; + --no-color) NO_COLOR=1 ;; + -?*) die "Unknown option: $1" ;; + *) break ;; + esac + shift + done + + args=("$@") + + + return 0 +} +# ----- Script Start ----- +# Parse parameters and setup colors for script. +parse_params "$@" +setup_colors + +# Script logic example here. + +git init --bare $HOME/.dot +alias config='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME' +config config --local status.showUntrackedFiles no +echo "alias config='/usr/bin/git --git-dir=$HOME/.dot/ --work-tree=$HOME'" >> $HOME/.bashrc + +exit 0