X-Git-Url: https://git.madduck.net/etc/zsh.git/blobdiff_plain/e25239284d7361795d6f0073c6f73fc0ddabc4b8..b0b97fc4ff5979996658d86faf08000478fa45ce:/.zsh/func/idiotheke?ds=sidebyside diff --git a/.zsh/func/idiotheke b/.zsh/func/idiotheke new file mode 100755 index 0000000..5a0d5d6 --- /dev/null +++ b/.zsh/func/idiotheke @@ -0,0 +1,32 @@ +#!/bin/sh +set -u + +if [ -n "${ZSH_VERSION:-}" ]; then + # don't execute trap on return from functions + setopt local_options posix_traps no_warn_create_global +fi + +RESOURCE=idiotheke.de +PASSWORD="$(pass $RESOURCE)" +LOGIN="$(echo "$PASSWORD" | sed -rne 's/login: //p')" +URL="$(echo "$PASSWORD" | sed -rne 's/url: //p')" +PASSWORD="${PASSWORD%% +*}" #first line only + +if [ -n "${1:-}" ]; then + ASKPASS="$(tempfile --prefix=askpass --mode=700)" + cleanup() { rm -f $ASKPASS; trap - 0; } + trap cleanup 0 + + echo '#!/bin/sh' >> $ASKPASS + echo "echo ${LOGIN}:${PASSWORD}" >> $ASKPASS + + wget --continue --use-askpass="$ASKPASS" "$@" + + cleanup + ! command -v unfunction >/dev/null || unfunction cleanup +else + LFTP_PASSWORD="$PASSWORD" lftp -e "open -u $LOGIN --env-password $URL" +fi + +unset RESOURCE LOGIN PASSWORD URL ASKPASS