]> git.madduck.net Git - etc/zsh.git/blob - .zsh/func/idiotheke

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

retire old-getpw
[etc/zsh.git] / .zsh / func / idiotheke
1 #!/bin/sh
2 set -u
3
4 if [ -n "${ZSH_VERSION:-}" ]; then
5   # don't execute trap on return from functions
6   setopt local_options posix_traps no_warn_create_global
7 fi
8
9 RESOURCE=idiotheke.de
10 PASSWORD="$(pass $RESOURCE)"
11 LOGIN="$(echo "$PASSWORD" | sed -rne 's/login: //p')"
12 URL="$(echo "$PASSWORD" | sed -rne 's/url: //p')"
13 PASSWORD="${PASSWORD%%
14 *}" #first line only
15
16 if [ -n "${1:-}" ]; then
17   ASKPASS="$(tempfile --prefix=askpass --mode=700)"
18   cleanup() { rm -f $ASKPASS; trap - 0; }
19   trap cleanup 0
20
21   echo '#!/bin/sh' >> $ASKPASS
22   echo "echo ${LOGIN}:${PASSWORD}" >> $ASKPASS
23
24   wget --continue --use-askpass="$ASKPASS" "$@"
25
26   cleanup
27   ! command -v unfunction >/dev/null || unfunction cleanup
28 else
29   LFTP_PASSWORD="$PASSWORD" lftp -e "open -u $LOGIN --env-password $URL"
30 fi
31
32 unset RESOURCE LOGIN PASSWORD URL ASKPASS