clean dead links
This commit is contained in:
parent
d45aacbead
commit
b7e9b356d8
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@
|
||||||
.devenv/
|
.devenv/
|
||||||
|
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
|
|
||||||
|
.plowcache
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
|
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
|
||||||
|
|
||||||
env.PLOW_FROM = "./home";
|
env.PLOW_FROM = "./home";
|
||||||
|
env.PLOW_CACHE = "./.plowcache";
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
./devenv.nix
|
./devenv.nix
|
||||||
|
|
|
@ -4,9 +4,30 @@ set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
|
progname="$0"
|
||||||
|
|
||||||
|
error() {
|
||||||
|
local line
|
||||||
|
for line in "$@"; do
|
||||||
|
echo "$progname: $line" 1>&2
|
||||||
|
done
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
shopt -s nullglob globstar
|
shopt -s nullglob globstar
|
||||||
|
|
||||||
opts=$(getopt --options f:t:Fivm: --longoptions=from:,to:,force,interactive,verbose,directory-mode: --name "$0" -- "$@")
|
if [[ ! -v PLOW_CACHE ]]; then
|
||||||
|
PLOW_CACHE=.plowcache
|
||||||
|
fi
|
||||||
|
|
||||||
|
opts=$(
|
||||||
|
getopt \
|
||||||
|
--options f:t:Fivm: \
|
||||||
|
--longoptions from:,to:,force,interactive,verbose,directory-mode: \
|
||||||
|
--name "$0" \
|
||||||
|
-- "$@"
|
||||||
|
)
|
||||||
|
|
||||||
eval set -- "$opts"
|
eval set -- "$opts"
|
||||||
|
|
||||||
|
@ -14,6 +35,7 @@ from=${PLOW_FROM:-$PWD}
|
||||||
to=${PLOW_TO:-$HOME}
|
to=${PLOW_TO:-$HOME}
|
||||||
lnflags=()
|
lnflags=()
|
||||||
mkdirflags=()
|
mkdirflags=()
|
||||||
|
rmflags=()
|
||||||
while true; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-f | --from)
|
-f | --from)
|
||||||
|
@ -26,15 +48,18 @@ while true; do
|
||||||
;;
|
;;
|
||||||
-F | --force)
|
-F | --force)
|
||||||
lnflags+=(--force)
|
lnflags+=(--force)
|
||||||
|
rmflags+=(--force)
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-i | --interactive)
|
-i | --interactive)
|
||||||
lnflags+=(--interactive)
|
lnflags+=(--interactive)
|
||||||
|
rmflags+=(--interactive)
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-v | --verbose)
|
-v | --verbose)
|
||||||
lnflags+=(--verbose)
|
lnflags+=(--verbose)
|
||||||
mkdirflags+=(--verbose)
|
mkdirflags+=(--verbose)
|
||||||
|
rmflags+=(--verbose)
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-m | --directory-mode)
|
-m | --directory-mode)
|
||||||
|
@ -62,13 +87,34 @@ fi
|
||||||
|
|
||||||
shopt -s dotglob
|
shopt -s dotglob
|
||||||
|
|
||||||
|
cache=()
|
||||||
|
if [[ -n "$PLOW_CACHE" ]]; then
|
||||||
|
if [[ -e "$PLOW_CACHE" ]]; then
|
||||||
|
while IFS= read -r link; do
|
||||||
|
cache+=("$link")
|
||||||
|
done < "$PLOW_CACHE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
: > "$PLOW_CACHE"
|
||||||
|
fi
|
||||||
|
|
||||||
for choice in "${choices[@]}"; do
|
for choice in "${choices[@]}"; do
|
||||||
prefix=$from/$choice
|
prefix=$from/$choice
|
||||||
for target in "$prefix"/**/*; do
|
for target in "$prefix"/**/*; do
|
||||||
if [[ -f "$target" ]]; then
|
if [[ -f "$target" ]]; then
|
||||||
link=$to${target#"$prefix"}
|
link=$to${target#"$prefix"}
|
||||||
mkdir --parents "${mkdirflags[@]}" -- "$(dirname -- "$link")"
|
parent=$(dirname -- "$link")
|
||||||
|
mkdir --parents "${mkdirflags[@]}" -- "$parent"
|
||||||
ln --symbolic "${lnflags[@]}" -- "$target" "$link"
|
ln --symbolic "${lnflags[@]}" -- "$target" "$link"
|
||||||
|
if [[ -n "$PLOW_CACHE" ]]; then
|
||||||
|
echo "$link" >> "$PLOW_CACHE"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
for link in "${cache[@]}"; do
|
||||||
|
if [[ -L "$link" && ! -f "$link" ]]; then
|
||||||
|
rm "${rmflags[@]}" -- "$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in a new issue