dotfiles/.config/zsh/functions/putwww

31 lines
704 B
Plaintext
Raw Normal View History

2022-03-19 06:27:22 +01:00
#!/usr/bin/env zsh
# Put files on a webspace via sftp
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
zmodload zsh/zutil
local -a o_dir=(-d "")
local -a o_help=()
zparseopts -D -K -- d:=o_dir h=o_help
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
2022-04-17 06:59:04 +02:00
local ret=$(( ${#o_help} ^ 1 ))
print -u $(( 1 + ${ret} )) "usage: ${0} [-h] [-d REMOTE SUBDIR] <FILE> …"
return ${ret}
fi
local dir=""
[[ -n ${o_dir[2]} ]] && dir=${o_dir[2]}/
2022-03-19 06:27:22 +01:00
local -a putcmds
for file in "${@}"; do
putcmds+="put ${file}"
done
sftp tastytea.de <<EOF
cd /var/www/tastytea.de/files/${dir}
2022-03-19 06:27:22 +01:00
$(print -l ${putcmds})
EOF
for file in "${@}"; do
print '\e[1;95m→\e[0m' https://tastytea.de/files/${dir}"${file##*/}"
2022-03-19 06:27:22 +01:00
done