#!/usr/bin/env bash THIS="$(dirname "$(readlink -fm "$0")")" FANCYFY="client" CURRENT_FANCYFY="" DELETE=false MOVE=false PRESENT=false _bashrc_present() { if [ ! -z "$(grep "#REF:bashrc_overrides:REF" ~/.bashrc)" ]; then echo true exit fi echo false } _arguments() { if [ "$(_bashrc_present)" = true ]; then PRESENT=true CURRENT_FANCYFY="$(grep TERMINAL_FANCYFY ~/.bashrc | sed 's/.*=//')" fi for PARM in "$@"; do if [ "${PARM}" = "--server" ]; then FANCYFY="server" elif [ "${PARM}" = "--delete" ]; then DELETE=true elif [ "${PARM}" = "--move" ]; then MOVE=true elif [ "${PARM}" = "-h" ] || [ "${PARM}" = "--help" ]; then _help exit 0 fi done } _help() { echo "Usage: $(readlink -fm "$0") [-h | --help] [--cleanup]" echo echo "Options:" echo " -h | --help" echo " Prints this help message and quits" echo " --force" echo " Force the reinstallation of the files" echo " --delete" echo " Delete the reference in ${BASHRC}" echo " --move" echo " Create a new reference if the location of this folder has been changed" echo " --server" echo " Customizes the terminal feel for a server installation" echo } _delete() { sed -i '/REF:bashrc_overrides:REF/{N;N;d}' ~/.bashrc } _bashrc_ref() { echo "#REF:bashrc_overrides:REF" >> ~/.bashrc echo "export TERMINAL_FANCYFY=${1}" >> ~/.bashrc echo ". ${THIS}/bashrc_overrides/_all" >> ~/.bashrc } _move() { _delete _bashrc_ref "${FANCYFY}" } _main() { _arguments "$@" if [ "${DELETE}" = true ]; then _delete echo "removed custom configs" elif [ "${MOVE}" = true ]; then if [ "${PRESENT}" = false ]; then _bashrc_ref "${FANCYFY}" echo "unable to move to current directory" echo "bash overrides not previously present" echo "adding bash overrides..." echo else _move echo "moved custom config directory to ${THIS}" echo fi elif [ "${PRESENT}" = true ]; then if [ "${CURRENT_FANCYFY}" != "${FANCYFY}" ]; then sed -i "s/TERMINAL_FANCYFY=${CURRENT_FANCYFY}/TERMINAL_FANCYFY=${FANCYFY}/" ~/.bashrc echo "customized fancyfying" echo else echo "bash overrides already in place" echo "skipping..." echo fi else _bashrc_ref "${FANCYFY}" echo "bash overrides added" echo fi } _main "$@"