#!/usr/bin/env bash EDITORCONFIG_PATH="$HOME/.editorconfig-generator" EDITORCONFIG_LIBRARY_DIR="$EDITORCONFIG_PATH/lib/editorconfig" EDITORCONFIG_SCRIPT_FILE="$EDITORCONFIG_PATH/lib/generator.rb" BIN_DIRECTORY="/usr/local/bin" GENERATOR_LOCATION="$BIN_DIRECTORY/generator" function echo_message() { echo "$1" } function remove_existing_generator() { if [ -f "$GENERATOR_LOCATION" ] ; then echo_message "Removing existing generator binary located at: [$GENERATOR_LOCATION]" if rm "$GENERATOR_LOCATION" ; then echo_message "Removed existing generator binary successfully." else echo_message "Unable to remove existing generator binary." fi else echo_message "[$GENERATOR_LOCATION] does not exist. Skipping removing binary..." fi } function link_generator() { if [ -f "$EDITORCONFIG_SCRIPT_FILE" ] && [ -d "$BIN_DIRECTORY" ] ; then echo_message "Symbolically linking [$EDITORCONFIG_SCRIPT_FILE] to [$GENERATOR_LOCATION]" if ln -sf "$EDITORCONFIG_SCRIPT_FILE" "$GENERATOR_LOCATION" ; then echo_message "Successfully linked the files" else echo_message "Unable to link the files" fi else echo_message "[$EDITORCONFIG_SCRIPT_FILE] or [$BIN_DIRECTORY] does not exist..." fi } function link_generator_directory() { if [ -d "$EDITORCONFIG_LIBRARY_DIR" ] && [ -d "$BIN_DIRECTORY" ] ; then echo_message "Symbolically linking [$EDITORCONFIG_LIBRARY_DIR] to [$BIN_DIRECTORY]" if ln -sf "$EDITORCONFIG_LIBRARY_DIR" "$BIN_DIRECTORY" ; then echo_message "Successfully linked the directories" else echo_message "Unable to link the directories" fi else echo_message "[$EDITORCONFIG_LIBRARY_DIR] or [$BIN_DIRECTORY] does not exist..." fi } function write_permissions_to_generator() { if [ -f "$GENERATOR_LOCATION" ] ; then if chmod +x "$GENERATOR_LOCATION" ; then echo_message "Sucessfully given write permissions to [$GENERATOR_LOCATION]" else echo_message "Unable to give write permissions to [$GENERATOR_LOCATION]" fi else echo_message "[$GENERATOR_LOCATION] doesn't exist" fi } remove_existing_generator link_generator link_generator_directory write_permissions_to_generator #ln -sf ~/.editorconfig-generator/lib/generator.rb /usr/local/bin/generator # Link the generator script to the bin path #chmod +x /usr/local/bin/generator # Give the script appropriate permissions # #ln -sf ~/.editorconfig-generator/lib/editorconfig /usr/local/bin # Link the supporting files to the binary location