This commit is contained in:
Vasili Svirydau
2021-04-16 13:43:22 -07:00
parent cc283d92bd
commit cf075eb3cc
7 changed files with 67 additions and 32 deletions

View File

@@ -9,41 +9,47 @@ function finish {
trap finish EXIT
function overlay {
local source="$1"
local prefix="$2"
cd "$source" || exit;
find . -maxdepth 1 -type f -printf "%f\0" | while IFS= read -r -d $'\0' P; do
local target="${prefix}/${P}"
local backup="${prefix}/${P}.orig.${timestamp}"
# echo "$PWD/$P" "->" "$target"
# skip existing links
if [ -h "$target" ]; then continue; fi
# move existing dir out of the way
if [ -e "$target" ]; then
if [ -e "$backup" ]; then
echo "want to override $target but backup exists"
continue;
fi
echo -n "Backup ${P}"
mv -v "$target" "$backup"
fi
# create link
ln -v -s "$PWD/$P" "$target"
# ensure permissions
chmod -R o-rwx,g-rwx "$target"
done
}
# From aaronjensen/dotfiles
DOTFILES=$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd || return)
cd "$DOTFILES/dotfiles" || exit;
find . -maxdepth 1 -type f -printf "%f\0" | while IFS= read -r -d $'\0' P; do
target="${HOME}/${P}"
backup="${HOME}/${P}.orig.${timestamp}"
# skip existing links
if [ -h "$target" ]; then continue; fi
# move existing dir out of the way
if [ -e "$target" ]; then
if [ -e "$backup" ]; then
echo "want to override $target but backup exists"
continue;
fi
echo -n "Backup ${P}"
mv -v "$target" "$backup"
fi
# create link
ln -v -s "$PWD/$P" "$target"
# ensure permissions
chmod -R o-rwx,g-rwx "$target"
done
overlay "$DOTFILES/dotfiles" "$HOME"
overlay "$DOTFILES/dotfiles/.config" "$HOME/.config"
# shellcheck source=/dev/null
for f in "$DOTFILES/setup.d/"*.sh; do source "$f"; done
unset f;
(
echo "for f in $DOTFILES/bash.d/*.sh; do source \"\$f\"; done"
echo "unset f"
) >> ~/.bashrc