From 08d5e15e1869f14ff66e4d9aa28a46d174d25192 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 10 Apr 2022 03:39:55 +0200 Subject: [PATCH] Add subdir and help options to putwww, add completion --- .config/zsh/completions/_putwww | 7 +++++++ .config/zsh/functions/putwww | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .config/zsh/completions/_putwww diff --git a/.config/zsh/completions/_putwww b/.config/zsh/completions/_putwww new file mode 100644 index 0000000..6b1a4b1 --- /dev/null +++ b/.config/zsh/completions/_putwww @@ -0,0 +1,7 @@ +#compdef putwww + +_arguments '-d[remote subdirectory]:directory' '-h[short help text]' '*:file:_files' + +# Local Variables: +# mode: shell-script +# End: diff --git a/.config/zsh/functions/putwww b/.config/zsh/functions/putwww index c18d315..ee1db0e 100755 --- a/.config/zsh/functions/putwww +++ b/.config/zsh/functions/putwww @@ -3,9 +3,17 @@ setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL -autoload -U die - -[[ ${ARGC} -eq 0 ]] && die 1 "Usage: ${0} …" +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] …" + 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 <