From 0e88034af8e2729f51b4e91e0cd73080143800a9 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 13 Sep 2022 22:40:35 +0200 Subject: curl new --- bin/curl | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 bin/curl (limited to 'bin/curl') 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' -- cgit v1.2.3-70-g09d2