Files
dotfiles/dev-env

121 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Adapted from https://github.com/ThePrimeagen/dev/blob/master/dev-env
#
# Copies configuration files to their appropriate places.
dry_run="0"
if [ -z "$XDG_CONFIG_HOME" ]; then
echo "no xdg config home"
echo "using ~/.config"
XDG_CONFIG_HOME=$HOME/.config
fi
if [ -z "$DEV_ENV" ]; then
echo "env var DEV_ENV needs to be present"
exit 1
fi
if [[ $1 =~ ^--dry ]]; then
dry_run="1"
fi
log() {
if [[ $dry_run == "1" ]]; then
echo "[DRY_RUN]: $1"
else
echo "$1"
fi
}
log "env: $DEV_ENV"
# Removes a destination directory and copies all files to the destination.
update_dirs() {
log "copying over files from: $1"
pushd $1 &>/dev/null
(
# Copy everything except systemd and zsh folders, they need treated differently.
configs=$(find . -mindepth 1 -maxdepth 1 -type d \( -name "systemd" -o -name "zsh" \) -prune -o -type d -print)
for c in $configs; do
directory=${2%/}/${c#./}
log " removing: rm -rf $directory"
if [[ $dry_run == "0" ]]; then
rm -rf $directory
fi
log " copying env: cp $c $2"
if [[ $dry_run == "0" ]]; then
cp -r ./$c $2
fi
done
)
popd &>/dev/null
}
# Removes a destination file and copies a single file to the destination.
copy() {
log "removing: $2"
if [[ $dry_run == "0" ]]; then
rm $2 &>/dev/null
fi
log "copying: $1 to $2"
if [[ $dry_run == "0" ]]; then
cp $1 $2
fi
}
# Copy all files from a directory into another directory.
copy_files() {
log "copying over files from: $1"
pushd $1 &>/dev/null
(
for f in $(find . -mindepth 1 -maxdepth 1 -type f); do
local dest="$2/$(basename $f)"
if [[ $dry_run == "0" ]]; then
rm -rf $dest >/dev/null 2>&1
fi
log " copying env: cp $f $dest"
if [[ $dry_run == "0" ]]; then
cp $f $dest
fi
done
)
popd &>/dev/null
}
############################## MAIN ##############################
update_dirs $DEV_ENV/env/.config $XDG_CONFIG_HOME
update_dirs $DEV_ENV/env/.local $HOME/.local
# SYSTEMD
mkdir -p $XDG_CONFIG_HOME/systemd/user
copy_files $DEV_ENV/env/.config/systemd/user $XDG_CONFIG_HOME/systemd/user
# ZSH
# NOTE: This keeps from clobbering zsh history and plugins vs. wiping the entire directory and
# copying configuration.
copy $DEV_ENV/env/.zshenv $HOME/.zshenv
mkdir -p $XDG_CONFIG_HOME/zsh
update_dirs $DEV_ENV/env/.config/zsh $XDG_CONFIG_HOME/zsh
copy_files $DEV_ENV/env/.config/zsh $XDG_CONFIG_HOME/zsh
# TMUX
copy $DEV_ENV/env/.tmux.conf $HOME/.tmux.conf
# GPG
mkdir $HOME/.gnupg
copy_files $DEV_ENV/env/.gnupg $HOME/.gnupg
copy $DEV_ENV/dev-env $HOME/.local/scripts/dev-env
systemctl --user daemon-reload
hyprctl reload