pip.plugin.zsh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Usage:
  2. # Just add pip to your installed plugins.
  3. # If you would like to change the cheeseshops used for autocomplete set
  4. # ZSH_PIP_INDEXES in your zshrc. If one of your indexes are bogus you won't get
  5. # any kind of error message, pip will just not autocomplete from them. Double
  6. # check!
  7. #
  8. # If you would like to clear your cache, go ahead and do a
  9. # "zsh-pip-clear-cache".
  10. ZSH_PIP_CACHE_FILE=~/.pip/zsh-cache
  11. ZSH_PIP_INDEXES=(https://pypi.python.org/simple/)
  12. zsh-pip-clear-cache() {
  13. rm $ZSH_PIP_CACHE_FILE
  14. unset piplist
  15. }
  16. zsh-pip-cache-packages() {
  17. if [[ ! -d ${PIP_CACHE_FILE:h} ]]; then
  18. mkdir -p ${PIP_CACHE_FILE:h}
  19. fi
  20. if [[ ! -f $ZSH_PIP_CACHE_FILE ]]; then
  21. echo -n "(...caching package index...)"
  22. tmp_cache=/tmp/zsh_tmp_cache
  23. for index in $ZSH_PIP_INDEXES ; do
  24. # well... I've already got two problems
  25. curl $index 2>/dev/null | \
  26. sed -nr '/^<a href/ s/.*>([^<]+).*/\1/p' \
  27. >> $tmp_cache
  28. done
  29. sort $tmp_cache | uniq | tr '\n' ' ' > $ZSH_PIP_CACHE_FILE
  30. rm $tmp_cache
  31. fi
  32. }