diff --git a/README.md b/README.md index 3fe2214..22b9d64 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Environment tweaks for everyday happiness. ## Setup ```bash -git clone git@github.com:mcataford/env.git | . ./setup +git clone git@github.com:mcataford/env.git | . ./install.sh ``` The setup script will look for pre-existing managed blocks and will not update the file if one is found. @@ -22,7 +22,7 @@ The package is structured as such: ``` env/ - setup # Adds bootstrap block to your shell's config file. + install.sh # Adds bootstrap block to your shell's config file. shell_extras # Functions, aliases and exports for the shell. extras.vim # Common config for NVIM. ``` diff --git a/setup b/install.sh similarity index 72% rename from setup rename to install.sh index 5b67141..402b85c 100644 --- a/setup +++ b/install.sh @@ -1,25 +1,26 @@ #!/bin/bash -set -e - -# -# Detects the current shell (bash, zsh, ...) and adds, if necessary, a managed -# block to its configuration to source extra files on shell-start. +# 1. PRECONDITIONS # +# zsh is expected to be set up. -BLOCK_DELIMITER_PATTERN="mcataford/env-managed-block" -WORKING_PATH=$(git rev-parse --show-toplevel) -SHELL_CONFIG_PATH="" - -# First, we need to know if we're dealing with ZSH or Bash. -if [[ -n $(echo $SHELL | grep zsh) ]]; then - SHELL_CONFIG_PATH="$HOME/.zshrc" -else - SHELL_CONFIG_PATH="$HOME/.bashrc" +if [ -z "$(zshc --version 2> /dev/null)" ]; then + echo "💥 Install zsh (https://www.zsh.org/) before installing environment." + return fi -# A managed block is added to source the `shell_extras` file -# in the shell configuration (either `.zshrc` or `.bashrc`). +# 2. CONFIGURATION INJECTION + +# 2.1 Inject shell configuration. +# +# Adds a managed block to the shell configuration to +# source extra files on shell-start. +# + +BLOCK_DELIMITER_PATTERN="mcataford/env" +WORKING_PATH=$(git rev-parse --show-toplevel) +SHELL_CONFIG_PATH="$HOME/.zshrc" + echo "Setting up shell configuration extras..." if [[ -z $(cat $SHELL_CONFIG_PATH | grep $BLOCK_DELIMITER_PATTERN) ]]; then echo "# $BLOCK_DELIMITER_PATTERN\:start @@ -33,8 +34,12 @@ fi EDITOR_CONFIG=$HOME/.config/nvim EDITOR_CONFIG_FILE=$EDITOR_CONFIG/init.vim +# 2.2 Inject nvim configuration. +# # Similarly, sourcing for `extras.vim` is added to the vim configuration # so plugins, bindings and whatnot are loaded on start. +# + if [[ -f $EDITOR_CONFIG_FILE ]]; then echo "Setting up NVIM configuration extras..." if [[ -z $(cat $EDITOR_CONFIG_FILE | grep $BLOCK_DELIMITER_PATTERN) ]]; then