Make copy_dotfiles POSIX, simplify zsh files, minor nvim changes

This commit is contained in:
2025-11-15 00:09:26 -06:00
parent f1700e1d3d
commit 7ef1d2f391
8 changed files with 63 additions and 61 deletions

View File

@@ -1,36 +1,37 @@
#!/bin/zsh
#!/bin/sh
echo_and_execute() { echo "executing: $@" && "$@" }
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
from=$1
to=$2
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
from=$1
to=$2
prev_dir=$(pwd)
cd "$from" || return 1
find . -mindepth 1 -maxdepth 1 -type d | while read -r dir; 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
find . -mindepth 1 -maxdepth 1 -type f | while read -r file; do
copy_file "$file" "$to"
done
popd > /dev/null
cd "$prev_dir" || return 1
}
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
! [ -e "$1" ] && echo "skipping link, target does not exist: $1" && return
[ -h "$2" ] && rm "$2"
test -f "$2" -o -d "$2" && rm -rf "$2"
echo_and_execute ln -s "$1" "$2"
}
echo "---- copying dotfiles ------------------"
@@ -47,12 +48,12 @@ 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
case "$OSTYPE" in *darwin*) copy_dir src_files/bin_overrides_macos $DIR_BIN;; esac
# 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"
IFS=","; 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