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"
79 if [ "$inhome" -ef "$ours" ]; then
80 good "already symlinked here"
81 elif [ -h "$inhome" ]; then
82 bad "wrong symlink target"
83 elif ! [ -e "$inhome" ]; then
84 needs setup "absent here"
85 $act ln -s "$linktarget" "$inhome"
86 elif [ -f "$inhome" ] && [ -f "$ours" ]; then
87 if cmp -s "$ours" "$inhome"; then
88 needs setup "identical in this ~ but not yet symlinked"
90 $act ln -s "$linktarget" "$inhome"~
91 $act mv -f "$inhome"~ "$inhome"
93 needs import "modified here"
95 $act cp "$inhome" "$ours"~
96 $act mv -f "$ours"~ "$ours"
98 elif [ -d "$inhome" ] && [ -d "$ours" ]; then
99 needs dirimport "directory in this ~, not yet symlinked"
100 $act mv "$ours" "$ours~"
101 $act ln -s "$linktarget" "$inhome"~
102 $act mv "$inhome" "$ours"
103 $act mv "$inhome~" "$inhome"
106 bad "mismatched file types"
110 dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' )
112 for ours in $dots; do
113 underhome=".${ours#dot/}"
117 nondots=$( find home -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' )
119 for ours in $nondots; do
120 underhome="${ours#home/}"
126 find -L .[0-9a-zA-Z]* -maxdepth 0 -xdev -type l \
127 \( -lname "$basepath/dot/*" -o -lname "$basepath/home/*" \)
129 for underhome in $brokens; do
130 inhome="$HOME/$underhome"
131 prhome="~/$underhome"
132 needs clean "symlink to removed file in dot/"