#!/usr/bin/bash current_time=$(date +"%d-%m-%Y-%H") log_filename="${current_time}.log" # Redirect stdout and stderr to the log file exec > >(tee -a "$log_filename") 2>&1 cd $HOME || { echo "Failed to change directory to $HOME"; exit 1; } # Run the 'chezmoi managed' command and save the output to a variable managed_files=$(chezmoi managed) if [ $? -ne 0 ]; then echo "Error during the execution of 'chezmoi managed'" exit 1 fi while IFS= read -r file; do # Run the 'chezmoi add' command for each file chezmoi add "$file" done <<< "$managed_files"