summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/curl43
1 files changed, 43 insertions, 0 deletions
diff --git a/bin/curl b/bin/curl
new file mode 100755
index 0000000..1570da6
--- /dev/null
+++ b/bin/curl
@@ -0,0 +1,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'