From ec7b60a377436a1f9db9f76e1dd82c0867975db8 Mon Sep 17 00:00:00 2001 From: PowerUser64 Date: Sun, 19 Sep 2021 16:45:25 -0700 Subject: [PATCH] added dotfiles init script (so you can make your own repo!) --- .local/bin/dotfiles-init.sh | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 .local/bin/dotfiles-init.sh diff --git a/.local/bin/dotfiles-init.sh b/.local/bin/dotfiles-init.sh new file mode 100755 index 0000000..a9dddcd --- /dev/null +++ b/.local/bin/dotfiles-init.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# this will setup a bare git repo for managing dotfiles. You should only run this script once per set of dotfiles. +# credit for this idea and basic script outline goes to: https://www.atlassian.com/git/tutorials/dotfiles + +set -e + +# name the path to the dotfiles repo +DOTFILES_REPO_DIR="$HOME/git/dotfiles" + +# Some colors to spice things up + Cyan="$( tput setaf 6 )" +Green="$( tput setaf 2 )" + NC="$( tput sgr0 )" # No Color + +# check for the git command and exit if it doesn't exist +if ! command -v git > /dev/null;then + echo 'git is not installed or could not be found in $PATH, please install git to proceed' + exit 1 +fi + +# an "alias" for the git command for use by the script +dot() { + git --git-dir="$DOTFILES_REPO_DIR" --work-tree="$HOME" "$@" +} + + +mkdir -p "$DOTFILES_REPO_DIR" +if git init --bare "$DOTFILES_REPO_DIR" > /dev/null 2>&1; then + echo "A bare git repository has been initialized at $DOTFILES_REPO_DIR" + echo +else + echo 'git repository initialization failed' + exit +fi +dot config --local status.showUntrackedFiles no +echo "Please add this alias to your shell's init script:" +# looks like this: alias dot="git --git-dir="/path/to/repo" --work-tree=\"$HOME\"" +echo " ${Cyan}alias dot=${Green}\"git --git-dir=\"$DOTFILES_REPO_DIR\" --work-tree=\\\"\$HOME\\\"\"${NC}" +echo "Then, you can use the command '${Cyan}dot ${Green}add ${NC}' to add a given file to the repo" +