1
0
Fork 0

Add subdir and help options to putwww, add completion

This commit is contained in:
tastytea 2022-04-10 03:39:55 +02:00
parent d2d2a166df
commit 08d5e15e18
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 20 additions and 5 deletions

View File

@ -0,0 +1,7 @@
#compdef putwww
_arguments '-d[remote subdirectory]:directory' '-h[short help text]' '*:file:_files'
# Local Variables:
# mode: shell-script
# End:

View File

@ -3,9 +3,17 @@
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
autoload -U die
[[ ${ARGC} -eq 0 ]] && die 1 "Usage: ${0} <file> …"
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
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]}/
local -a putcmds
for file in "${@}"; do
@ -13,10 +21,10 @@ for file in "${@}"; do
done
sftp tastytea.de <<EOF
cd /var/www/tastytea.de/files/
cd /var/www/tastytea.de/files/${dir}
$(print -l ${putcmds})
EOF
for file in "${@}"; do
print '\e[1;95m→\e[0m' https://tastytea.de/files/"${file##*/}"
print '\e[1;95m→\e[0m' https://tastytea.de/files/${dir}"${file##*/}"
done