3 # To start tracking a file,
4 # cp ~/.screenrc dot/screenrc
6 # To sort out symlinks when things are clean
7 # infra/makelinks install
9 set -e -o posix -o pipefail
12 echo >&2 "usage: $0 [-n|-v] list|setup|dirimport|dirmove|clean"
19 if [ $# = 0 ]; then break; fi
21 -n) real_act=log_only ;;
22 -v) real_act=with_log ;;
30 1.list|1.setup|1.import|1.dirimport|1.clean) ;;
37 basepath=${basepath#$HOME/}
46 if [ $mode = list ]; then
47 show "good: $prhome: $1"
53 show "bad: $prhome: $1" >&2
57 if [ $mode = $1 ]; then
59 show "DOING $1: $prhome ($2)"
61 show "needs $1: $prhome: $2"
76 inhome="$HOME/$underhome"
78 linktarget="$basepath/$ours"
83 linktarget="../$linktarget"
91 if [ "$inhome" -ef "$ours" ]; then
92 good "already symlinked here"
93 elif [ -h "$inhome" ]; then
94 bad "wrong symlink target"
95 elif ! [ -e "$inhome" ]; then
96 needs setup "absent here"
97 $act ln -s "$linktarget" "$inhome"
98 elif [ -f "$inhome" ] && [ -f "$ours" ]; then
99 if cmp -s "$ours" "$inhome"; then
100 needs setup "identical in this ~ but not yet symlinked"
101 $act rm -f "$inhome"~
102 $act ln -s "$linktarget" "$inhome"~
103 $act mv -f "$inhome"~ "$inhome"
105 needs import "modified here"
107 $act cp "$inhome" "$ours"~
108 $act mv -f "$ours"~ "$ours"
110 elif [ -d "$inhome" ] && [ -d "$ours" ]; then
111 needs dirimport "directory in this ~, not yet symlinked"
112 $act mv "$ours" "$ours~"
113 $act ln -s "$linktarget" "$inhome"~
114 $act mv "$inhome" "$ours"
115 $act mv "$inhome~" "$inhome"
118 bad "mismatched file types"
122 dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' )
124 for ours in $dots; do
125 underhome=".${ours#dot/}"
129 nondots=$( find home -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' )
131 for ours in $nondots; do
132 underhome="${ours#home/}"
136 exec 3<correspondences
137 while read <&3 ours underhome; do
143 parent=${underhome%/*}
144 punderhome="$HOME/$parent"
145 prhome="~/${underhome%/*}"
146 if [ -d "$punderhome" ]; then
147 good "directory exists"
148 elif ! [ -e "$punderhome" ]; then
149 needs setup "directory does not exist"
150 $act mkdir -p "$punderhome"
152 bad "ought to be director but isn't"
163 find -L .[0-9a-zA-Z]* -maxdepth 0 -xdev -type l \
164 \( -lname "$basepath/dot/*" -o -lname "$basepath/home/*" \)
166 for underhome in $brokens; do
167 inhome="$HOME/$underhome"
168 prhome="~/$underhome"
169 needs clean "symlink to removed file in dot/"