dotfiles/.config/zsh/functions/puttmpninja

24 lines
721 B
Plaintext
Raw Normal View History

2022-04-14 01:02:18 +02:00
#!/usr/bin/env zsh
2022-04-14 04:55:05 +02:00
# Put files on tmp.ninja
2022-04-14 01:02:18 +02:00
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
zmodload zsh/zutil
local -a o_help=()
zparseopts -D -K -- h=o_help
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
local ret=$(( ${#o_help} ^ 1 ))
2022-04-14 01:02:18 +02:00
print -u $(( 1 + ${ret} )) -l "usage: ${0} [-h] <FILE> …" \
"\e[3mFiles on tmp.ninja expire after 48 hours.\e[0m"
return ${ret}
fi
for file in ${@}; do
print -Pn '%F{12}'
2022-04-14 01:02:18 +02:00
local url=$(curl --progress-bar --form "files[]=@${file}" \
'https://tmp.ninja/upload.php?output=text')
[[ ${url} == "" ]] && return 1
print -P '%B%F{13}→%f%b' "%F{15}${url}%f" \
2022-04-14 02:56:11 +02:00
"\e[3;90mexpires: $(date --date='now + 2 days')\e[0m"
2022-04-14 01:02:18 +02:00
done