public
Description: My configuration files for various applications
Homepage: http://mina86.com/
Clone URL: git://github.com/mina86/dot-files.git
mina86 (author)
Fri Oct 16 02:33:17 -0700 2009
commit  f20802d27bfc52da3bc4038a3042d3ccb058f875
tree    ee7f0243169d09a22185614288afec6b9cd6c5aa
parent  ba198f5843b077cbeff5ad542b8cccd33dc706d2
dot-files / update
100755 180 lines (160 sloc) 3.038 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#! /bin/sh
 
set -e
 
 
##
## Usage
##
usage () {
cat <<EOF
usage: $0 [ <options> ] [ <files> ]
<options>:
-f updat files in current directory from configuration files
-t updat configuration files from files in current directory
-b make backup (default) -B do not make backups
-i interactive (default) -I not interactive
EOF
exit 1
}
 
 
##
## Parse arguments
##
DIRECTION=
INTERACTIVE=yes
BACKUP=yes
 
while [ x"${1#-}" != x"$1" ]; do
ARG=${1#?}
shift
while [ -n "$ARG" ]; do
case "$ARG" in
f*) DIRECTION=from ;;
t*) DIRECTION=to ;;
b*) BACKUP=yes ;;
B*) BACKUP= ;;
i*) INTERACTIVE=yes;;
I*) INTERACTIVE= ;;
?*) usage ;;
esac
ARG=${ARG#?}
done
done
 
[ -n "$DIRECTION" ] || usage
 
 
##
## Print info
##
case "$DIRECTION" in
from) echo 'Updating files in current directory from configuration files' ;;
to) echo 'Updating configuration files from files in current directory' ;;
*) usage
esac
 
case "$INTERACTIVE" in '')
printf 'Do you want to continue? [y/N] '
if ! read answer; then
exit 0
elif [ X"${answer#[yY]}" = X"${answer}" ]; then
exit 0
fi
esac
 
 
##
## File arguments
##
if [ $# -eq 0 ]; then
match () {
return 0
}
else
match () {
for f in "$@"; do
case "$FILE" in "$f")
return 0
esac
done
return 1
}
fi
 
 
##
## Interactive asking
##
if [ -n "$INTERACTIVE" ]; then
difference () {
case "$1" in [dD])
set -- r "$3" "$2"
esac
if which cdiff >/dev/null 2>&1; then
cdiff -u "$2" "$3"
else
diff -u "$2" "$3"
fi
}
 
ask () {
while :; do
printf '%s: [yndre?] ' "$2"
read answer || exit 0
case "$answer" in
[yY]) return 0 ;;
[nN]) return 1 ;;
[dDrR]) difference $answer "$1" "$2" ;;
[eE]) exit 0 ;;
'?') echo 'y - copy, n - skip, d - diff, r - reverse diff, e - exit'
esac
done
}
else
ask() {
return 0
}
fi
 
 
##
## Backup & copy
##
case "$BACKUP" in
yes)
cp_backup () {
if ! [ -e "$2" ]; then
cp -v -- "$1" "$2"
elif ! cmp -s -- "$1" "$2" && ask "$1" "$2"; then
mv -- "$2" "$2~"
cp -v -- "$1" "$2"
fi
}
;;
*)
cp_backup () {
if ! [ -e "$2" ]; then
cp -v -- "$1" "$2"
elif ! cmp -s -- "$1" "$2" && ask "$1" "$2"; then
cp -v -- "$1" "$2"
fi
}
esac
 
 
##
## Do the job
##
while read FILE DEST; do
if match "$@"; then
case "$DEST" in '~'*) DEST=$HOME${DEST#'~'}; esac
case "$DEST" in */.|*/) DEST=$DEST$FILE; esac
if ! [ -d "${DEST%/*}" ]; then
echo "Skipping $FILE"
else
case "$DIRECTION" in
from) cp_backup "$DEST" "$FILE" <&3 ;;
to) cp_backup "$FILE" "$DEST" <&3 ;;
esac
fi
fi
done 3<&1 <<EOF
Xresources ~/.
bash_profile ~/.
bashrc ~/.
dot-emacs ~/.emacs.d/init.el
dot-gnus ~/.gnus/.gnus.el
gitconfig ~/.
irssi.theme ~/.irssi/mina.theme
profile ~/.
risc-mode.el ~/.emacs.d/elisp/
sawfishrc ~/.
shellrc ~/.
statuses ~/.irssi/
term ~/bin/
xinitrc ~/.
zshrc ~/.
EOF