mirror of
https://github.com/nix-community/home-manager
synced 2024-12-02 16:09:46 +01:00
home-environment: interactively inspect non-managed files
This commit is contained in:
parent
89dc8c2004
commit
2b74fbde2e
1 changed files with 31 additions and 9 deletions
|
@ -251,9 +251,37 @@ in
|
||||||
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
|
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
|
||||||
let
|
let
|
||||||
pattern = "-home-manager-files/";
|
pattern = "-home-manager-files/";
|
||||||
check = pkgs.writeText "check" ''
|
diff = "${pkgs.diffutils}/bin/diff -r --suppress-common-lines --color=always";
|
||||||
|
pager = "${pkgs.less}/bin/less -R";
|
||||||
|
ls = "${pkgs.exa}/bin/exa --color=always";
|
||||||
|
check = pkgs.writeScript "check" ''
|
||||||
. ${./lib-bash/color-echo.sh}
|
. ${./lib-bash/color-echo.sh}
|
||||||
|
|
||||||
|
handleCollision () {
|
||||||
|
printf "`errorEcho 'Existing file '`"
|
||||||
|
printf "`${ls} $targetPath`"
|
||||||
|
errorEcho " is in the way"
|
||||||
|
while : ; do
|
||||||
|
printf "`warnEcho 'Overwrite? [y]es, [N]o, [v]iew, [d]iff '`"
|
||||||
|
read < /dev/tty
|
||||||
|
if [ "$REPLY" = v ] || [ "$REPLY" = V ] ; then
|
||||||
|
if [ -d "$targetPath" ] ; then
|
||||||
|
${ls} -l "$targetPath/" | ${pager} || true
|
||||||
|
else
|
||||||
|
${pager} "$targetPath" || true
|
||||||
|
fi
|
||||||
|
elif [ "$REPLY" = d ] || [ "$REPLY" = D ] ; then
|
||||||
|
${diff} "$targetPath" "$newGenFiles/$relativePath" | ${pager} || true
|
||||||
|
elif [ "$REPLY" = y ] || [ "$REPLY" = Y ] ; then
|
||||||
|
rm -rf "$file"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
errorEcho "Please move the above files and try again"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
newGenFiles="$1"
|
newGenFiles="$1"
|
||||||
shift
|
shift
|
||||||
for sourcePath in "$@" ; do
|
for sourcePath in "$@" ; do
|
||||||
|
@ -261,15 +289,9 @@ in
|
||||||
targetPath="$HOME/$relativePath"
|
targetPath="$HOME/$relativePath"
|
||||||
if [[ -e "$targetPath" \
|
if [[ -e "$targetPath" \
|
||||||
&& ! "$(readlink "$targetPath")" =~ "${pattern}" ]] ; then
|
&& ! "$(readlink "$targetPath")" =~ "${pattern}" ]] ; then
|
||||||
errorEcho "Existing file '$targetPath' is in the way"
|
handleCollision "$targetPath"
|
||||||
collision=1
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -v collision ]] ; then
|
|
||||||
errorEcho "Please move the above files and try again"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
|
@ -277,7 +299,7 @@ in
|
||||||
local newGenFiles
|
local newGenFiles
|
||||||
newGenFiles="$(readlink -e "$newGenPath/home-files")"
|
newGenFiles="$(readlink -e "$newGenPath/home-files")"
|
||||||
find "$newGenFiles" -type f -print0 -or -type l -print0 \
|
find "$newGenFiles" -type f -print0 -or -type l -print0 \
|
||||||
| xargs -0 bash ${check} "$newGenFiles"
|
| xargs -0 ${check} "$newGenFiles"
|
||||||
}
|
}
|
||||||
|
|
||||||
checkNewGenCollision || exit 1
|
checkNewGenCollision || exit 1
|
||||||
|
|
Loading…
Reference in a new issue