added dotfiles init script (so you can make your own repo!)

This commit is contained in:
PowerUser64 2021-09-19 16:45:25 -07:00
parent 2a3001ac6d
commit 1976e6dd4a

40
.local/bin/dotfiles-init.sh Executable file
View file

@ -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 <file>${NC}' to add a given file to the repo"