Skip to content

Instantly share code, notes, and snippets.

@augustohp
Last active October 22, 2023 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save augustohp/0b0f96249e399d4ec731830280fbe776 to your computer and use it in GitHub Desktop.
Save augustohp/0b0f96249e399d4ec731830280fbe776 to your computer and use it in GitHub Desktop.
Homeshick bootstrap script
#!/usr/bin/env bash
# Author: Devin Waever <https://github.com/sukima>
# Author: Augusto Pascutti <augusto.hp+oss@gmail.com>
# Original source: https://github.com/sukima/dotfiles/blob/gh-pages/homeshick.sh
# For Windows : https://gist.github.com/augustohp/15183d64bcba18a9a773b7402ea63801
# Fork source : https://gist.github.com/augustohp/0b0f96249e399d4ec731830280fbe776
#
# Installs homeshick and clones castles of interest
# Usage: bash <(curl -Ls https://git.io/fNMTH)
set -eo pipefail
GIT=$(which git)
tmpfilename="/tmp/${0##*/}.XXXXX"
test -z "$GIT" && { echo "Error: Git is not installed."; exit 2; }
if type mktemp >/dev/null
then
tmpfile=$(mktemp $tmpfilename)
else
tmpfile=$(echo $tmpfilename | sed "s/XX*/$RANDOM/")
fi
trap 'rm -f "$tmpfile"' EXIT
cat <<'EOF' > $tmpfile
# Which Homeshick castles do you want to install?
#
# Each line is passed as the argument(s) to `homeshick clone`.
# Lines starting with '#' will be ignored.
# Git must be able to access these repositories, if you put private
# repositories on the list be sure to have access configured.
# You can CTRL-Z, do it, and `fg` to come back and complete the process.
#
# If you remove or comment a line that castle will NOT be installed.
# However, if you remove or comment everything, the script will be aborted.
# Plugin management
git@github.com:augustohp/warwick.git
git@github.com:augustohp/warwick-vim.git
git@github.com:augustohp/ore-docker-php.git
git@github.com:augustohp/ore-gitlab_cli.git
EOF
${VISUAL:-vi} $tmpfile
code=$?
if [[ $code -ne 0 ]]; then
echo "Editor returned ${code}." 1>&2
exit 2
fi
castles=()
while read line
do
castle=$(echo "$line" | sed '/^[ \t]*#/d;s/^[ \t]*\(.*\)[ \t]*$/\1/')
if [[ -n $castle ]]
then
castles+=("$castle")
fi
done <$tmpfile
if [[ ${#castles[@]} -eq 0 ]]
then
echo "No castles to install. Aborting."
exit 0
fi
if [[ ! -f $HOME/.homesick/repos/homeshick/homeshick.sh ]]; then
echo "Homeshick not found, installing it..."
mkdir -p $HOME/.homesick/repos/
$GIT clone git@github.com:andsens/homeshick.git $HOME/.homesick/repos/homeshick
fi
source $HOME/.homesick/repos/homeshick/homeshick.sh
for castle in "${castles[@]}"; do
homeshick clone --force "$castle"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment