blob: 1570da670fd6395fc002ef55e23dd676970ab73d (
plain)
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
|
#!/bin/bash
usage() {
>&2 echo 'usage: '"$0"' -o file url'
exit
}
if [ "$#" -ne 3 ] || [ ! "x$1" = 'x-o' ]; then
usage
fi
file="$2"
url=$(
printf -- '%s' "${3}" \
| base64 -w0
)
work_dir=$(readlink -e "$0")
work_dir="${work_dir%/*/*}/work"
if [ ! -d "${work_dir}" ]; then
mkdir "${work_dir}"
echo 'files' >"${work_dir}"'/.gitignore'
git -C "${work_dir}" init
git -C "${work_dir}" add '.gitignore'
git -C "${work_dir}" commit -m 'initial commit'
fi
if [ -s "${work_dir}/files/${url}" ]; then
cp "${work_dir}/files/${url}" "${file}"
exit
fi
{
printf -- '%s\n' "${url}"
[ -s "${work_dir}/wishlist" ] \
&& cat "${work_dir}/wishlist"
} \
| sort -u \
| sponge "${work_dir}/wishlist"
git -C "${work_dir}" add 'wishlist'
git -C "${work_dir}" commit -m 'new wishes'
|