2021-05-08 14:42:53 +00:00
|
|
|
#!/bin/bash
|
2020-03-23 00:42:02 +00:00
|
|
|
|
2023-12-16 05:43:31 +00:00
|
|
|
# 1. PRECONDITIONS
|
|
|
|
#
|
|
|
|
# zsh is expected to be set up.
|
|
|
|
|
|
|
|
if [ -z "$(zshc --version 2> /dev/null)" ]; then
|
|
|
|
echo "💥 Install zsh (https://www.zsh.org/) before installing environment."
|
|
|
|
return
|
|
|
|
fi
|
2022-11-12 00:44:21 +00:00
|
|
|
|
2023-12-16 05:43:31 +00:00
|
|
|
# 2. CONFIGURATION INJECTION
|
|
|
|
|
|
|
|
# 2.1 Inject shell configuration.
|
2022-11-04 17:37:25 +00:00
|
|
|
#
|
2023-12-16 05:43:31 +00:00
|
|
|
# Adds a managed block to the shell configuration to
|
|
|
|
# source extra files on shell-start.
|
2022-11-04 17:37:25 +00:00
|
|
|
#
|
|
|
|
|
2023-12-16 05:43:31 +00:00
|
|
|
BLOCK_DELIMITER_PATTERN="mcataford/env"
|
2023-05-29 04:31:52 +00:00
|
|
|
WORKING_PATH=$(git rev-parse --show-toplevel)
|
2023-12-16 05:43:31 +00:00
|
|
|
SHELL_CONFIG_PATH="$HOME/.zshrc"
|
2020-03-23 00:42:02 +00:00
|
|
|
|
2022-11-12 00:44:21 +00:00
|
|
|
echo "Setting up shell configuration extras..."
|
2022-11-05 16:53:26 +00:00
|
|
|
if [[ -z $(cat $SHELL_CONFIG_PATH | grep $BLOCK_DELIMITER_PATTERN) ]]; then
|
2022-11-12 00:47:09 +00:00
|
|
|
echo "# $BLOCK_DELIMITER_PATTERN\:start
|
2023-05-29 04:31:52 +00:00
|
|
|
source $WORKING_PATH/shell_extras
|
2022-11-12 00:47:09 +00:00
|
|
|
# $BLOCK_DELIMITER_PATTERN\:end" >> $SHELL_CONFIG_PATH
|
2022-11-12 00:44:21 +00:00
|
|
|
echo "✅ Added managed block to $SHELL_CONFIG_PATH"
|
|
|
|
else
|
|
|
|
echo "No changes to apply!"
|
2022-11-05 16:53:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
EDITOR_CONFIG=$HOME/.config/nvim
|
|
|
|
EDITOR_CONFIG_FILE=$EDITOR_CONFIG/init.vim
|
|
|
|
|
2023-12-16 05:43:31 +00:00
|
|
|
# 2.2 Inject nvim configuration.
|
|
|
|
#
|
2023-05-29 04:31:52 +00:00
|
|
|
# Similarly, sourcing for `extras.vim` is added to the vim configuration
|
|
|
|
# so plugins, bindings and whatnot are loaded on start.
|
2023-12-16 05:43:31 +00:00
|
|
|
#
|
|
|
|
|
2022-11-05 16:53:26 +00:00
|
|
|
if [[ -f $EDITOR_CONFIG_FILE ]]; then
|
2022-11-12 00:44:21 +00:00
|
|
|
echo "Setting up NVIM configuration extras..."
|
2022-11-05 16:53:26 +00:00
|
|
|
if [[ -z $(cat $EDITOR_CONFIG_FILE | grep $BLOCK_DELIMITER_PATTERN) ]]; then
|
2022-11-12 00:47:09 +00:00
|
|
|
echo "\" $BLOCK_DELIMITER_PATTERN\:start
|
2023-05-29 04:31:52 +00:00
|
|
|
source $WORKING_PATH/extras.vim
|
2022-11-12 00:47:09 +00:00
|
|
|
\" $BLOCK_DELIMITER_PATTERN\:end\n\n" >> $EDITOR_CONFIG_FILE.new
|
2022-11-05 16:53:26 +00:00
|
|
|
cat $EDITOR_CONFIG_FILE >> $EDITOR_CONFIG_FILE.new
|
|
|
|
|
|
|
|
mv $EDITOR_CONFIG_FILE $EDITOR_CONFIG_FILE.old
|
|
|
|
mv $EDITOR_CONFIG_FILE.new $EDITOR_CONFIG_FILE
|
2022-11-12 00:44:21 +00:00
|
|
|
echo "✅ Added managed block to $EDITOR_CONFIG_FILE"
|
|
|
|
else
|
|
|
|
echo "No changes to apply!"
|
2022-11-05 16:53:26 +00:00
|
|
|
fi
|
2021-05-08 14:42:53 +00:00
|
|
|
fi
|
2022-11-12 00:44:21 +00:00
|
|
|
|
|
|
|
echo "Setting up git configuration..."
|
|
|
|
source $WORKING_PATH/git_config
|
|
|
|
echo "✅ Set up git configuration, see $WORKING_PATH/git_config for details!"
|
|
|
|
|