Refactor copy_configs, improve sym-linking; vim configs fine for now

This commit is contained in:
2025-02-01 13:45:06 -06:00
parent defcd11e06
commit 3eb6f67184
4 changed files with 42 additions and 27 deletions

View File

@ -3,18 +3,6 @@
execute() { log "execute $@" && "$@" }
log() { echo "$@" }
copy_dir() {
local from=$1
local to=$2
pushd $from > /dev/null
local dirs=(`find . -mindepth 1 -maxdepth 1 -type d`)
for dir in $dirs; do
[[ -d $to/$dir ]] && execute rm -rf $to/$dir
execute cp -rp $dir $to/$dir
done
popd > /dev/null
}
copy_file() {
local from=$1
local to=$2
@ -23,20 +11,42 @@ copy_file() {
execute cp -p $from $to/$filename
}
log "---------------- dotfiles ----------------"
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 ]] && execute rm -rf $to/$dir
execute cp -rp $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
}
copy_dir src_files/.config $XDG_CONFIG_HOME
copy_dir src_files/.local $DIR_LOCAL
link_dir() {
local src_dir=$1
local link_dir=$2
log "deleting existing link/dir: $link_dir"
[[ -h "$link_dir" ]] && rm $link_dir
[[ -d "$link_dir" ]] && rm -rf $link_dir
log "sym-linking $link_dir -> $src_dir"
ln -s $src_dir $link_dir
}
log "---------------- dotfiles ----------------"
copy_file src_files/.config/zsh/.zshenv $HOME # duplicate, copy anyway, ensures $ZDOTDIR
# on macos, handle sim-linking to gimp config since gimp defaults to app-support
if [[ "$BOX_SETUP_OS" = "macos" ]]; then
local macos_gimp_dir="$HOME/Library/Application Support/GIMP"
log "deleting existing GIMP link/dir: $macos_gimp_dir"
[[ -h "$macos_gimp_dir" ]] && rm $macos_gimp_dir
[[ -d "$macos_gimp_dir" ]] && rm -rf $macos_gimp_dir
log "linking $macos_gimp_dir to \$XDG_CONFIG_HOME/GIMP"
ln -s $XDG_CONFIG_HOME/GIMP $macos_gimp_dir
fi
copy_dir src_files/.config $XDG_CONFIG_HOME
copy_dir src_files/.local/bin $DIR_BIN
copy_dir src_files/.local/scripts $DIR_SCRIPTS
# on macos, gimp defaults to app-support, so sym-link to actual config
[[ "$BOX_SETUP_OS" = "macos" ]] &&
link_dir "$XDG_CONFIG_HOME/GIMP" "$HOME/Library/Application Support/GIMP"
link_dir "$XDG_CONFIG_HOME/vim" "$HOME/.vim" # TODO: use vim wrapper or similar instead