chiark / gitweb /
Prepare for home/: move dots=, change uses of $dot to $ours and provide $linktarget...
[ian-dotfiles.git] / infra / makelinks
index 6bcf4d94ae2855e0e1636199ff04d78f9929082a..dd167d31a200fcda856a91e3568a4a79670c275c 100755 (executable)
@@ -33,8 +33,6 @@ esac
 
 mode=$1; shift
 
-dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' )
-
 basepath=$(pwd)
 basepath=${basepath#$HOME/}
 
@@ -74,36 +72,40 @@ with_log () {
     "$@"
 }
 
+dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' )
+
 for dot in $dots; do
+    ours="$dot"
     underhome=".${dot#dot/}"
     inhome="$HOME/$underhome"
     prhome="~/$underhome"
-    if [ "$inhome" -ef "$dot" ]; then
+    linktarget="$basepath/$ours"
+    if [ "$inhome" -ef "$ours" ]; then
        good "already symlinked here"
     elif [ -h "$inhome" ]; then
         bad "wrong symlink target"
     elif ! [ -e "$inhome" ]; then
        needs setup "absent here"
        $act ln -s "$basepath/$dot" "$inhome"
-    elif [ -f "$inhome" ] && [ -f "$dot" ]; then
-       if cmp -s "$dot" "$inhome"; then
+    elif [ -f "$inhome" ] && [ -f "$ours" ]; then
+       if cmp -s "$ours" "$inhome"; then
            needs setup "identical here but not yet symlinked"
            $act rm -f "$inhome"~
-           $act ln -s "$basepath/$dot" "$inhome"~
+           $act ln -s "$linktarget" "$inhome"~
            $act mv -f "$inhome"~ "$inhome"
        else
            needs import "modified here"
-           $act rm -f "$dot"~
-           $act cp "$inhome" "$dot"~
-           $act mv -f "$dot"~ "$dot"
+           $act rm -f "$ours"~
+           $act cp "$inhome" "$ours"~
+           $act mv -f "$ours"~ "$ours"
        fi
-    elif [ -d "$inhome" ] && [ -d "$dot" ]; then
+    elif [ -d "$inhome" ] && [ -d "$ours" ]; then
        needs dirimport "directory here not yet symlinked"
-       $act mv "$dot" "$dot~"
-       $act ln -s "$basepath/$dot" "$inhome"~
-       $act mv "$inhome" "$dot"
+       $act mv "$ours" "$ours~"
+       $act ln -s "$linktarget" "$inhome"~
+       $act mv "$inhome" "$ours"
        $act mv "$inhome~" "$inhome"
-       $act rm -rf "$dot~"
+       $act rm -rf "$ours~"
     else
        bad "mismatched file types"
     fi