57 lines
876 B
Bash
57 lines
876 B
Bash
#! /bin/bash
|
|
|
|
google() (
|
|
_is_sheets() {
|
|
echo "$@" | grep -q 'docs.google.com.spreadsheets'
|
|
}
|
|
|
|
_is_doc() {
|
|
echo "$@" | grep -q 'docs.google.com.document'
|
|
}
|
|
|
|
is() {
|
|
_is_sheets "$@" || _is_doc "$@"
|
|
}
|
|
|
|
human_url() {
|
|
echo "$1"
|
|
}
|
|
|
|
get() {
|
|
local url="$1"
|
|
local id="${url%/*}"
|
|
id="${id##*/}"
|
|
local downloaded="$(rclone get_google "$id")"
|
|
echo "# ${downloaded##*/}"
|
|
echo ""
|
|
if [ "${downloaded##*.}" == "csv" ]; then
|
|
_csv_to_md "$downloaded"
|
|
else
|
|
cat "$downloaded"
|
|
fi
|
|
}
|
|
|
|
_csv_to_md() {
|
|
local f="$1"
|
|
(
|
|
head -n 1 "$f"
|
|
head -n 1 "$f" \
|
|
| sed 's/^[^,][^,]*/--- /' \
|
|
| sed 's/[^,][^,]*$/ ---/' \
|
|
| sed 's/,[^,][^,]*/, --- /g' \
|
|
| sed 's/[^|]$/|/'
|
|
tail -n +2 "$f"
|
|
) \
|
|
| grep . \
|
|
| sed 's/,/ | /g' \
|
|
| sed 's/^/| /'
|
|
}
|
|
|
|
expand() {
|
|
get "$@" | head -n 1 | sed 's/^[#]* //' | base64
|
|
}
|
|
|
|
"$@"
|
|
)
|
|
|