2022-02-03
This commit is contained in:
parent
f86b8496ec
commit
db393215ce
55 changed files with 1907 additions and 0 deletions
54
bin/dotfiles.sh
Executable file
54
bin/dotfiles.sh
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env bash
|
||||
SWD="$(dirname "$(realpath "$0")")"
|
||||
|
||||
function rebase-fs() {
|
||||
# disable null glob because empty dirs will break
|
||||
# globbing and return the glob char '*'
|
||||
shopt -s nullglob
|
||||
local src_path=$1 dst_path=$2 file stat
|
||||
[[ -d "${src_path}" ]] && stat="d"
|
||||
[[ -f "${src_path}" ]] && stat="f"
|
||||
echo "${src_path}" "${dst_path}" "${stat}"
|
||||
case ${stat} in
|
||||
d)
|
||||
for file in "${src_path}"/*; do
|
||||
local path="${file/#${src_path}/${dst_path}}"
|
||||
rebase-fs "${file}" "${path}"
|
||||
done
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function mirror-fs() {
|
||||
local func_f="${1:?""}" func_d="${2:-"$1"}"
|
||||
local src dst typ
|
||||
while read -r src dst typ; do
|
||||
dst="${dst//\/dot-/\/.}"
|
||||
case ${typ} in
|
||||
d) "${func_d}" "${src}" "${dst}" "${typ}" ;;
|
||||
f) "${func_f}" "${src}" "${dst}" "${typ}" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function clone-d() {
|
||||
local src="${1:?""}" dst="${2:?""}" typ="${3:?""}"
|
||||
case ${typ} in
|
||||
d) command -p mkdir --parent "${dst}" ;;
|
||||
f) command -p cp --update "${src}" "${dst}" ;;
|
||||
esac
|
||||
command -p mkdir --parent "${dst}"
|
||||
command -p chmod --reference="${src}" "${dst}"
|
||||
}
|
||||
|
||||
function clone-f() {
|
||||
local src="${1:?""}" dst="${2:?""}" typ="${3:?""}"
|
||||
if [[ ${src} = *.localhost && -e ${dst} ]]; then
|
||||
printf "skipping local file %s\n" "${dst}"
|
||||
return
|
||||
fi
|
||||
command -p cp --update "${src}" "${dst}"
|
||||
}
|
||||
|
||||
SRC="$(realpath "${SWD}/../home")"
|
||||
rebase-fs "${SRC}" "${HOME}" | mirror-fs 'clone-f' 'clone-d'
|
Loading…
Add table
Add a link
Reference in a new issue