dotfiles/.config/zsh/functions/mxc2http

25 lines
671 B
Plaintext
Raw Normal View History

2022-04-16 06:31:59 +02:00
#!/usr/bin/env zsh
# Converts mxc:// URLs into https:// URLs
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
zmodload zsh/zutil
local -a o_help=()
2022-04-16 15:28:13 +02:00
local -a o_server=()
zparseopts -D -K -- h=o_help -server:=o_server
2022-04-16 06:31:59 +02:00
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
2022-04-17 06:59:04 +02:00
local ret=$(( ${#o_help} ^ 1 ))
2022-04-16 06:31:59 +02:00
print -u $(( 1 + ${ret} )) "usage: ${0} [-h] <URL> …"
return ${ret}
fi
local -a urls=(${@})
for url in ${urls}; do
local domain=${${url%/*}##*/}
2022-04-16 15:28:13 +02:00
local server=${domain}
[[ ${#o_server} -eq 2 ]] && server=${o_server[2]}
2022-04-16 06:31:59 +02:00
local id=${url##*/}
print '\e[1;95m→\e[0m' \
2022-04-16 15:28:13 +02:00
"https://${server}/_matrix/media/r0/download/${domain}/${id}"
2022-04-16 06:31:59 +02:00
done