#!/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"