#!/bin/bash

# exit this script if any error occurs
set -e

# get the directory where this script is in
SCRIPTDIR="$(realpath -s "$(dirname "$0")")"

HTOP_CONFIG_FILE="${SCRIPTDIR}/htoprc"
HTOP_CONFIG_TARGET="${HOME}/.config/htop/htoprc"

# check if target file exists
if [ -f "${HTOP_CONFIG_TARGET}" ]; then
  echo -e "INFO: found existing htop configuration!\n backing it up:"
  mv -v "${HTOP_CONFIG_TARGET}" "${HTOP_CONFIG_TARGET}.bak"
fi

# copying the config file
mkdir -v -p "$(dirname "${HTOP_CONFIG_TARGET}")"
cp -v "${HTOP_CONFIG_FILE}" "${HTOP_CONFIG_TARGET}"

# exit the script with zero exit code
exit 0
