#!/usr/bin/env bash

set -eu


# -- Create log file.

LOG_FILE="$HOME/.plasmashell_restart.log"
exec > >(tee -a "$LOG_FILE") 2>&1


# -- Define the source and target file paths.

source_file="/etc/skel/.config/mimeapps.list"
target_file="$HOME/.config/mimeapps.list"


# -- Check if the target file already exists.

if [ ! -f "$target_file" ]; then
    echo "The file $target_file does not exist. Attempting to copy from $source_file..."

    mkdir -p "$(dirname "$target_file")"

    if cp "$source_file" "$target_file"; then
        echo "File copied successfully."
    else
        echo "Error: Failed to copy the file." >&2
        exit 1
    fi
else
    echo "The file $target_file already exists. No action taken."
fi
