Skip to content

Instantly share code, notes, and snippets.

@nwhatt
Forked from r0adkll/lolconfigure.sh
Last active April 24, 2019 16:42
Show Gist options
  • Save nwhatt/880b5b5fddf4eadfbeb0a3404e037f88 to your computer and use it in GitHub Desktop.
Save nwhatt/880b5b5fddf4eadfbeb0a3404e037f88 to your computer and use it in GitHub Desktop.
Setup lolcommits with optional animation and slack integration
#!/bin/bash
# Post-Commit hook text
post_commit_hook_base='#!/bin/sh
### lolcommits hook (begin) ###
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export PATH="/usr/bin:/usr/local/bin:$PATH"\n'
post_commit_hook_suffix='\n### lolcommits hook (end) ###'
lolcommits='lolcommits --capture --fork'
animate=' --animate='
post_commit_hook_file="$HOME/.git_template/hooks/post-commit"
echo ""
echo "########################################"
echo "# You are now installing Redox #"
echo "# lolcommit setup #"
echo " __________ .___ "
echo " \______ \ ____ __| _/_______ ___ "
echo " | _// __ \ / __ |/ _ \ \/ / "
echo " | | \ ___// /_/ ( <_> > < "
echo " |____|_ /\___ >____ |\____/__/\_ \ "
echo "# #"
echo "########################################"
echo ""
# Here we go.. ask for the administrator password upfront and run a
# keep-alive to update existing `sudo` time stamp until script has finished
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Check for Homebrew,
# Install if we don't have it
if test ! $(which brew); then
echo "Installing homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Update homebrew recipes
brew update
# Install imagemagick
echo "Installing Imagemagick..."
brew install imagemagick
# Install FFMpeg
echo "Installing ffmpeg..."
brew install ffmpeg
# Install LOLCommits: NEEDS TO BE RAN AS SUDO
if test ! $(which lolcommits); then
echo "Installing lolcommits..."
sudo gem install lolcommits
fi
echo "Installing lolcommits-slack"
sudo gem install lolcommits-slack
echo "Setting up slack integration (follow prompts)"
lolcommits --config -p slack
echo "Configuring Git..."
# Create GIT Template directory
mkdir -p ~/.git_template/hooks
git config --global init.templatedir '~/.git_template'
# Get user's animation count in seconds
echo ""
echo "Enter the duration of the animation (<= 0 for images only): "
read input
if [ $input -eq $input 2>/dev/null ]
then
githook=$post_commit_hook_base$lolcommits
if [ $input -gt 0 ]
then
githook+=$animate$input
fi
githook+=$post_commit_hook_suffix
echo -e "$githook" > $post_commit_hook_file
echo "Git hook post-commit template created @ $post_commit_hook_file"
else
echo "Error: Invalid animation duration"
exit 1
fi
lolcommits --enable
echo \"Re-configuring Git Hook...\"
cp -f ~/.git_template/hooks/post-commit .git/hooks/post-commit
# Calculate the location of the configuration
################################################################################
# Get the name of the working directory, ideally this script should be executed
# in the directory of the project you are trying to setup
project=\${PWD##*/}
# Concatentate the lol project directory
lolcommit_dir=\"\$HOME/.lolcommits/\$project\"
# Create the directory
mkdir -p \$lolcommit_dir
# Now write the configuration to the config.yml file
config_file=\$lolcommit_dir'/'\$config_file_name
# Fin
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment