Skip to content

Instantly share code, notes, and snippets.

@bewuethr
Last active November 11, 2023 18:13
Show Gist options
  • Save bewuethr/4d044f84989cb430a8b9c46dc4ea75c9 to your computer and use it in GitHub Desktop.
Save bewuethr/4d044f84989cb430a8b9c46dc4ea75c9 to your computer and use it in GitHub Desktop.
Dotfiles initialization script
#!/usr/bin/env bash
while getopts 'l:' opt; do
case $opt in
l) branch=$OPTARG ;;
*) exit 1 ;;
esac
done
if [[ -n $branch ]]; then
repo='dotfiles-local.git'
else
repo='dotfiles.git'
fi
# Clone repository as bare repository
git clone --bare "git@github.com:bewuethr/$repo" ".$repo"
# Set local repo configuration
git -C ".$repo" config user.name 'Benjamin Wuethrich'
git -C ".$repo" config user.email 'benjamin.wuethrich@gmail.com'
git -C ".$repo" config status.showUntrackedFiles no
git -C ".$repo" config core.sparseCheckout true
cat <<- EOF > ".$repo/info/sparse-checkout"
/*
!README.md
!LICENSE
!.github/dependabot.yml
EOF
# Check out files - this overwrites existing files
git --git-dir=".$repo" --work-tree=. checkout --force "${branch:-main}"
# Initialize submodules
git --git-dir=".$repo" --work-tree=. submodule update --init
# Set upstream
git --git-dir=".$repo" --work-tree=. push --set-upstream origin "${branch:-main}"
@bewuethr
Copy link
Author

bewuethr commented Aug 12, 2019

Remarks

  • This is the installation script for these dotfiles and their local counterparts.

  • This can be run anywhere and will install the dotfiles in the current directory, but it is really meant to be run in $HOME.

  • If you're not me, the user and email settings won't make a lot of sense.

  • This is destructive! If you want to preserve your existing dotfiles, back them up first.

  • To get the local dotfiles, use the -l option with the desired branch name (see example below).

  • Using the raw link to this Gist, initializing on a new machine takes just

    cd "$HOME"
    bash <(curl -L https://git.io/JJczn)
    bash <(curl -L https://git.io/JJczn) -l t460s

    to get the common dotfiles and the local ones for branch t460s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment