#!/bin/zsh echo_and_execute() { echo "executing: $@" && "$@" } copy_file() { local from=$1 local to=$2 local filename=$(basename $from) [[ -e $to/$filename ]] && rm $to/$filename echo_and_execute cp -RPp $from $to/$filename } copy_dir() { local from=$1 local to=$2 pushd $from > /dev/null local directories=(`find . -mindepth 1 -maxdepth 1 -type d`) for dir in $directories; do [[ -d $to/$dir ]] && rm -rf $to/$dir echo_and_execute cp -RPp $dir $to/$dir done local files=(`find . -mindepth 1 -maxdepth 1 -type f`) for file in $files; do copy_file $file $to done popd > /dev/null } sym_link() { [[ ! -e "$1" ]] && echo "skipping link, target does not exist: $1" && return [[ -h "$2" ]] && rm $2 [[ -f "$2" || -d "$2" ]] && rm -rf $2 echo_and_execute ln -s $1 $2 } echo "---- copying dotfiles ------------------" source src_files/.config/zsh/.zshenv copy_file src_files/.config/zsh/.zshenv $HOME # copy first, ensure $ZDOTDIR set # configs/executables/scripts from .config and .local copy_dir src_files/.config $XDG_CONFIG_HOME copy_dir src_files/.local/bin $DIR_BIN copy_dir src_files/.local/scripts $DIR_SCRIPTS # macOS overrides as needed [[ "$OSTYPE" = *"darwin"* ]] && copy_dir src_files/bin_overrides_macos $DIR_BIN # obsidian uses a per-vault config model, so copy to all target vaults/dirs for obs_dir in "${OBSIDIAN_WORKSPACES_TO_CONFIGURE[@]}"; do [[ ! -d "$obs_dir/.obsidian" ]] && mkdir "$obs_dir/.obsidian" copy_dir $XDG_CONFIG_HOME/obsidian "$obs_dir/.obsidian" done # TODO: get reaper config set up # [[ $1 = "studio-music" ]] { # [[ "$OSTYPE" = *"darwin"* ]] && # sym_link "$XDG_CONFIG_HOME/REAPER" "$HOME/Library/Application Support/REAPER" # }